9 changed files with 250 additions and 20 deletions
@ -0,0 +1,97 @@ |
|||||
|
package cc.hiver.mall.controller; |
||||
|
|
||||
|
import cc.hiver.core.common.utils.ResultUtil; |
||||
|
import cc.hiver.core.common.vo.Result; |
||||
|
import cc.hiver.core.entity.User; |
||||
|
import cc.hiver.core.service.UserService; |
||||
|
import cc.hiver.mall.entity.Customer; |
||||
|
import cc.hiver.mall.service.mybatis.CustomerService; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@Api(tags = "客户接口") |
||||
|
@RequestMapping(value = "/hiver/app/customer/") |
||||
|
@Transactional |
||||
|
public class CustomerController { |
||||
|
@Autowired |
||||
|
private CustomerService customerService; |
||||
|
|
||||
|
@Autowired |
||||
|
private UserService userService; |
||||
|
|
||||
|
@RequestMapping(value = "/save", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "新增客户") |
||||
|
public Result save(Customer customer) { |
||||
|
|
||||
|
String encryptPass = new BCryptPasswordEncoder().encode(customer.getPassword()); |
||||
|
customer.setPassword(encryptPass); |
||||
|
boolean result = customerService.save(customer); |
||||
|
User user = new User(); |
||||
|
user.setUsername(customer.getName()); |
||||
|
user.setAddress(customer.getAddress()); |
||||
|
user.setType(2);//客户
|
||||
|
user.setMobile(customer.getPhone()); |
||||
|
user.setPassword(encryptPass); |
||||
|
userService.save(user); |
||||
|
if(result) { |
||||
|
return ResultUtil.success("添加成功"); |
||||
|
} else { |
||||
|
return ResultUtil.error("添加失败"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// @RequestMapping(value = "/edit", method = RequestMethod.POST)
|
||||
|
// @ApiOperation(value = "根据客户id修改客户")
|
||||
|
// public Result edit(Customer customer) {
|
||||
|
//
|
||||
|
// boolean result = customerService.updateById(customer);
|
||||
|
// if(result) {
|
||||
|
// return ResultUtil.success("修改成功");
|
||||
|
// } else {
|
||||
|
// return ResultUtil.error("修改失败");
|
||||
|
// }
|
||||
|
// }
|
||||
|
|
||||
|
@RequestMapping(value = "/delById", method = RequestMethod.POST) |
||||
|
@ApiOperation(value = "根据id删除客户") |
||||
|
public Result delete(Customer customer) { |
||||
|
boolean result = customerService.removeById(customer); |
||||
|
if(result) { |
||||
|
return ResultUtil.success("删除成功"); |
||||
|
} else { |
||||
|
return ResultUtil.error("删除失败"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@RequestMapping(value = "/list", method = RequestMethod.GET) |
||||
|
@ApiOperation(value = "查询客户列表") |
||||
|
public Result list() { |
||||
|
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>(); |
||||
|
List<Customer> list = customerService.list(queryWrapper); |
||||
|
return new ResultUtil<List<Customer>>().setData(list); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/listByName", method = RequestMethod.GET) |
||||
|
@ApiOperation(value = "根据客户名称查询客户列表") |
||||
|
public Result listByName(String name) { |
||||
|
QueryWrapper<Customer> queryWrapper = new QueryWrapper<>(); |
||||
|
queryWrapper.like("name",name); |
||||
|
List<Customer> list = customerService.list(queryWrapper); |
||||
|
return new ResultUtil<List<Customer>>().setData(list); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
package cc.hiver.mall.service.mybatis; |
||||
|
|
||||
|
import cc.hiver.mall.entity.Customer; |
||||
|
import cc.hiver.mall.entity.Product; |
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
|
||||
|
public interface CustomerService extends IService<Customer> { |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package cc.hiver.mall.serviceimpl.mybatis; |
||||
|
|
||||
|
import cc.hiver.mall.dao.mapper.CustomerMapper; |
||||
|
import cc.hiver.mall.dao.mapper.ProductMapper; |
||||
|
import cc.hiver.mall.entity.Customer; |
||||
|
import cc.hiver.mall.entity.Product; |
||||
|
import cc.hiver.mall.service.mybatis.CustomerService; |
||||
|
import cc.hiver.mall.service.mybatis.ProductService; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService { |
||||
|
} |
||||
Loading…
Reference in new issue