You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-spms-java/src/main/java/com/glxp/api/controller/sup/CustomerController.java

212 lines
9.3 KiB
Java

package com.glxp.api.controller.sup;
import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.annotation.Log;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BusinessType;
import com.glxp.api.dto.DictDto;
import com.glxp.api.entity.auth.*;
import com.glxp.api.entity.purchase.CustomerContactEntity;
import com.glxp.api.entity.system.CompanyEntity;
import com.glxp.api.req.auth.CustomerInfoFilterRequest;
import com.glxp.api.req.system.DeleteRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.service.auth.AuthAdminService;
import com.glxp.api.service.auth.AuthRoleAdminService;
import com.glxp.api.service.auth.CustomerInfoService;
import com.glxp.api.service.purchase.CustomerContactService;
import com.glxp.api.service.system.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@Slf4j
public class CustomerController {
@Resource
private CompanyService companyService;
@Resource
private CustomerInfoService customerInfoService;
@Resource
private CustomerContactService customerContactService;
// @Resource
// private UserRegisterService userRegisterService;
@Resource
private AuthAdminService authAdminService;
@Resource
private AuthRoleAdminService authRoleAdminService;
@AuthRuleAnnotation("")
@GetMapping("/spms/customer/list")
public BaseResponse filterCustomers(CustomerInfoFilterRequest customerFilterRequest) {
List<CustomerInfoEntity> customerDetailEntities = customerInfoService.filterCustomerInfo(customerFilterRequest);
PageInfo<CustomerInfoEntity> pageInfo;
pageInfo = new PageInfo<>(customerDetailEntities);
PageSimpleResponse<CustomerInfoEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(customerDetailEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("/spms/customer/listOptimize")
public BaseResponse filterCustomersOptimize(CustomerInfoFilterRequest customerFilterRequest) {
List<CustomerInfoEntity> customerDetailEntities = customerInfoService.filterCustomerInfo(customerFilterRequest);
List<DictDto> reList = customerDetailEntities.stream().map(s-> {
DictDto dictDto = new DictDto(s.getCustomerId().toString(),s.getCompanyName());
return dictDto;
}).collect(Collectors.toList());
PageInfo<DictDto> pageInfo;
pageInfo = new PageInfo<>(reList);
PageSimpleResponse<DictDto> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(reList);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("salewarehouse/customer/list")
public BaseResponse filterList(CustomerInfoFilterRequest customerFilterRequest) {
List<CustomerDetailEntity> customerDetailEntities = customerInfoService.filterDetailCustomer(customerFilterRequest);
PageInfo<CustomerDetailEntity> pageInfo;
pageInfo = new PageInfo<>(customerDetailEntities);
PageSimpleResponse<CustomerDetailEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(customerDetailEntities);
for (CustomerDetailEntity customerDetailEntity : customerDetailEntities) {
CompanyEntity companyEntity = companyService.findCompany(customerDetailEntity.getCustomerId());
if (companyEntity != null) {
customerDetailEntity.setFilePath(companyEntity.getFilePath());
}
}
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("salewarehouse/customer/detail")
public BaseResponse customerDetail(CustomerInfoFilterRequest customerFilterRequest) {
CustomerDetailEntity customerDetailEntity = customerInfoService.selectDetail(customerFilterRequest.getCustomerId());
if (customerDetailEntity != null) {
return ResultVOUtils.success(customerDetailEntity);
}
return ResultVOUtils.error(500, "用户信息为空");
}
@AuthRuleAnnotation("")
@PostMapping("salewarehouse/customer/update")
@Log(title = "客户信息", businessType = BusinessType.UPDATE)
public BaseResponse updateCustomer(@RequestBody @Valid CustomerDetailEntity customerDetailEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
CustomerInfoEntity customerInfoEntity = new CustomerInfoEntity();
BeanUtil.copyProperties(customerDetailEntity, customerInfoEntity);
customerInfoEntity.setCustomerId((Long.valueOf(customerDetailEntity.getCustomerId())));
boolean b = customerInfoService.updateCustomerInfo(customerInfoEntity);
//同时修改用户关联的角色
List<AuthAdmin> byCustomerld = authAdminService.findByCustomerld(customerDetailEntity.getCustomerId());
AuthRoleAdmin authRoleAdmin = new AuthRoleAdmin();
List<AuthRoleAdmin> objects = new ArrayList<>();
if( byCustomerld !=null && byCustomerld.size()>0){
for (AuthAdmin authAdmin : byCustomerld) {
//修改关联的用户状态
authAdmin.setUserFlag(customerDetailEntity.getUserFlag());
authAdminService.updateAuthAdmin(authAdmin);
List<AuthRoleAdmin> authRoleAdmins = authRoleAdminService.listByAdminId(authAdmin.getId());
if(authRoleAdmins!=null && authRoleAdmins.size()>0) {
authRoleAdmin.setRole_id(Long.valueOf(customerDetailEntity.getRoleId()));
authRoleAdmin.setUser_id(authAdmin.getId());
authRoleAdminService.updateAuthRoleAdmin(authRoleAdmin);
}else{
authRoleAdmin.setRole_id(Long.valueOf(customerDetailEntity.getRoleId()));
authRoleAdmin.setUser_id(authAdmin.getId());
objects.add(authRoleAdmin);
authRoleAdminService.insertAuthRoleAdminAll(objects);
}
}
}
if (customerDetailEntity.getUserFlag() != null) {
UpdateUserflagBean userflagBean = new UpdateUserflagBean();
userflagBean.setCustomerId(customerDetailEntity.getCustomerId());
userflagBean.setUserFlag(customerDetailEntity.getUserFlag());
}
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("更新成功");
}
@AuthRuleAnnotation("")
@PostMapping("salewarehouse/customer/modify")
@Log(title = "客户信息", businessType = BusinessType.UPDATE)
public BaseResponse modifyCustomer(@RequestBody @Valid CustomerDetailEntity customerDetailEntity,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
CustomerInfoEntity customerInfoEntity = new CustomerInfoEntity();
BeanUtil.copyProperties(customerDetailEntity, customerInfoEntity);
boolean b = customerInfoService.updateCustomerInfo(customerInfoEntity);
CustomerContactEntity customerContactEntity = new CustomerContactEntity();
BeanUtil.copyProperties(customerDetailEntity, customerContactEntity);
boolean c = customerContactService.updateCustomerContact(customerContactEntity);
if (!b) {
return ResultVOUtils.error(ResultEnum.NOT_NETWORK);
}
return ResultVOUtils.success("更新成功");
}
@AuthRuleAnnotation("")
@PostMapping("salewarehouse/customer/delete")
@Log(title = "客户信息", businessType = BusinessType.DELETE)
public BaseResponse deleteCustomers(@RequestBody DeleteRequest deleteRequest, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
String id = deleteRequest.getId();
customerInfoService.deleteById(id);
customerContactService.deleteById(id);
// userRegisterService.deleteByCustomerId(Long.parseLong(id));
authAdminService.deleteByCustomerId(id);
companyService.deleteCompany(Long.parseLong(id));
return ResultVOUtils.success("删除成功");
}
}