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.
379 lines
17 KiB
Java
379 lines
17 KiB
Java
package com.glxp.api.controller.purchase;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.extra.pinyin.PinyinUtil;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
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.ConstantStatus;
|
|
import com.glxp.api.entity.auth.*;
|
|
import com.glxp.api.entity.basic.BasicCorpEntity;
|
|
import com.glxp.api.entity.purchase.CustomerContactEntity;
|
|
import com.glxp.api.entity.purchase.SupCertEntity;
|
|
import com.glxp.api.entity.purchase.SupCertSetEntity;
|
|
import com.glxp.api.entity.purchase.SupCompanyEntity;
|
|
import com.glxp.api.exception.JsonException;
|
|
import com.glxp.api.req.purchase.FilterCertSetsRequest;
|
|
import com.glxp.api.req.purchase.FilterSupCertRequest;
|
|
import com.glxp.api.req.purchase.FilterSupCompanyRequest;
|
|
import com.glxp.api.req.purchase.SelectCorpBindRequest;
|
|
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.auth.ISysRoleService;
|
|
import com.glxp.api.service.basic.BasicCorpService;
|
|
import com.glxp.api.service.purchase.CustomerContactService;
|
|
import com.glxp.api.service.purchase.SupCertService;
|
|
import com.glxp.api.service.purchase.SupCertSetService;
|
|
import com.glxp.api.service.purchase.SupCompanyService;
|
|
import com.glxp.api.util.CustomUtil;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
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 org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.ListIterator;
|
|
|
|
@RestController
|
|
public class SupCompanyController {
|
|
|
|
@Value("${file_path}")
|
|
private String filePath;
|
|
|
|
@Resource
|
|
private AuthAdminService authAdminService;
|
|
@Resource
|
|
private SupCompanyService companyService;
|
|
@Resource
|
|
private CustomerContactService customerContactService;
|
|
@Resource
|
|
private SupCertService supCertService;
|
|
@Resource
|
|
BasicCorpService basicCorpService;
|
|
@Resource
|
|
SupCertSetService supCertSetService;
|
|
@Resource
|
|
SupCompanyService supCompanyService;
|
|
@Resource
|
|
CustomerInfoService customerInfoService;
|
|
@Resource
|
|
AuthRoleAdminService authRoleAdminService;
|
|
|
|
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@GetMapping("/api/pur/getSupComapnys")
|
|
public BaseResponse getSupComapnys(FilterSupCompanyRequest companyRequest) {
|
|
List<SupCompanyEntity> companyEntities = companyService.filterCompany(companyRequest);
|
|
PageInfo<SupCompanyEntity> pageInfo = new PageInfo<>(companyEntities);
|
|
PageSimpleResponse<SupCompanyEntity> pageSimpleResponse = new PageSimpleResponse<>();
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
pageSimpleResponse.setList(companyEntities);
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/api/pur/addCompany")
|
|
public BaseResponse insertCompany(@RequestBody SupCompanyEntity companyEntity) {
|
|
|
|
|
|
//判断是不是存在草稿
|
|
if (companyEntity.getAuditStatus() == 6) {
|
|
List<SupCertEntity> supCertEntityList = supCertService.findAll(companyEntity.getCustomerId());
|
|
for (SupCertEntity obj : supCertEntityList) {
|
|
if (obj.getAuditStatus() == 0) {
|
|
return ResultVOUtils.error(999, "证书中存在草稿不允许提交!");
|
|
}
|
|
}
|
|
|
|
//提交审核
|
|
FilterCertSetsRequest filterCertSetsRequest = new FilterCertSetsRequest();
|
|
filterCertSetsRequest.setType(ConstantStatus.CERT_COMPANY);
|
|
filterCertSetsRequest.setNeed(1);
|
|
List<SupCertSetEntity> supCertSetEntities = supCertSetService.filterCertSets(filterCertSetsRequest);
|
|
|
|
//验证
|
|
ListIterator<SupCertSetEntity> iterable = supCertSetEntities.listIterator();
|
|
while (iterable.hasNext()) {
|
|
SupCertSetEntity supCertSetEntity = iterable.next();
|
|
if (supCertSetEntity.isNeed()) {
|
|
for (SupCertEntity supCertEntity : supCertEntityList) {
|
|
if (supCertEntity.getName().equals(supCertSetEntity.getName())) {
|
|
if (StrUtil.isNotEmpty(supCertEntity.getFilePath())) {
|
|
iterable.remove();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
String errMsg = "";
|
|
if (supCertSetEntities.size() > 0) {
|
|
for (SupCertSetEntity supCertSetEntity : supCertSetEntities) {
|
|
errMsg = errMsg + "," + supCertSetEntity.getName();
|
|
}
|
|
return ResultVOUtils.error(500, errMsg.substring(1) + "等证书未上传,无法提交审核!");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
String customerId = CustomUtil.getId(); //重新生成customerId
|
|
CustomerContactEntity customerContactEntity = new CustomerContactEntity();
|
|
customerContactEntity.setTel(companyEntity.getTel());
|
|
customerContactEntity.setMobile(companyEntity.getMobile());
|
|
customerContactEntity.setEmail(companyEntity.getEmail());
|
|
customerContactEntity.setContacts(companyEntity.getContacts());
|
|
customerContactEntity.setCustomerId(customerId);
|
|
customerContactService.insertCustomerContact(customerContactEntity);
|
|
//更新相关证书对应的customerId
|
|
supCertService.updateCustomerId(companyEntity.getCustomerId(), customerId, ConstantStatus.AUDIT_UN);
|
|
companyEntity.setCustomerId(customerId);
|
|
|
|
companyEntity.setCreateTime(new Date());
|
|
companyEntity.setUpdateTime(new Date());
|
|
AuthAdmin authAdmin = getUser();
|
|
companyEntity.setCreateBy(authAdmin.getId() + "");
|
|
boolean b = companyService.insertCompany(companyEntity);
|
|
return ResultVOUtils.success("修改成功");
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/api/pur/modifyCompany")
|
|
public BaseResponse modifyCompany(@RequestBody SupCompanyEntity companyEntity) {
|
|
if (companyEntity.getAuditStatus() == ConstantStatus.AUDIT_UN || companyEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE) {
|
|
|
|
//判断是不是存在草稿
|
|
List<SupCertEntity> supCertEntityList = supCertService.findAll(companyEntity.getCustomerId());
|
|
for (SupCertEntity obj : supCertEntityList) {
|
|
if (obj.getAuditStatus() == 0) {
|
|
return ResultVOUtils.error(999, "证书中存在草稿不允许提交!");
|
|
}
|
|
}
|
|
|
|
//提交审核
|
|
FilterCertSetsRequest filterCertSetsRequest = new FilterCertSetsRequest();
|
|
filterCertSetsRequest.setType(ConstantStatus.CERT_COMPANY);
|
|
filterCertSetsRequest.setNeed(1);
|
|
List<SupCertSetEntity> supCertSetEntities = supCertSetService.filterCertSets(filterCertSetsRequest);
|
|
|
|
//验证
|
|
ListIterator<SupCertSetEntity> iterable = supCertSetEntities.listIterator();
|
|
while (iterable.hasNext()) {
|
|
SupCertSetEntity supCertSetEntity = iterable.next();
|
|
if (supCertSetEntity.isNeed()) {
|
|
for (SupCertEntity supCertEntity : supCertEntityList) {
|
|
if (supCertEntity.getName().equals(supCertSetEntity.getName())) {
|
|
if (StrUtil.isNotEmpty(supCertEntity.getFilePath())) {
|
|
iterable.remove();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
String errMsg = "";
|
|
if (supCertSetEntities.size() > 0) {
|
|
for (SupCertSetEntity supCertSetEntity : supCertSetEntities) {
|
|
errMsg = errMsg + "," + supCertSetEntity.getName();
|
|
}
|
|
return ResultVOUtils.error(500, errMsg.substring(1) + "等证书未上传,无法提交审核!");
|
|
}
|
|
}
|
|
|
|
|
|
companyEntity.setUpdateTime(new Date());
|
|
boolean b = companyService.modifyCompany(companyEntity);
|
|
CustomerContactEntity customerContactEntity = new CustomerContactEntity();
|
|
customerContactEntity.setTel(companyEntity.getTel());
|
|
customerContactEntity.setMobile(companyEntity.getMobile());
|
|
customerContactEntity.setEmail(companyEntity.getEmail());
|
|
customerContactEntity.setContacts(companyEntity.getContacts());
|
|
customerContactEntity.setCustomerId(companyEntity.getCustomerId());
|
|
customerContactService.updateCustomerContact(customerContactEntity);
|
|
return ResultVOUtils.success("修改成功");
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/api/pur/auditCompany")
|
|
public BaseResponse auditCompany(@RequestBody SupCompanyEntity companyEntity) {
|
|
|
|
|
|
if (companyEntity.getAuditStatus() == 1) {
|
|
//查询用户上传的证书
|
|
FilterSupCertRequest filterSupCertRequest = new FilterSupCertRequest();
|
|
filterSupCertRequest.setCustomerId(companyEntity.getCustomerId());
|
|
filterSupCertRequest.setType(ConstantStatus.CERT_COMPANY);
|
|
List<SupCertEntity> supCertEntityList = supCertService.filterCompanyCert(filterSupCertRequest);
|
|
|
|
//查询用户该上传的证书
|
|
FilterCertSetsRequest filterCertSetsRequest = new FilterCertSetsRequest();
|
|
filterCertSetsRequest.setType(ConstantStatus.CERT_COMPANY);
|
|
filterCertSetsRequest.setNeed(1);
|
|
List<SupCertSetEntity> supCertSetEntities = supCertSetService.filterCertSets(filterCertSetsRequest);
|
|
|
|
//验证
|
|
ListIterator<SupCertSetEntity> iterable1 = supCertSetEntities.listIterator();
|
|
while (iterable1.hasNext()) {
|
|
SupCertSetEntity supCertSetEntity = iterable1.next();
|
|
if (supCertSetEntity.isNeed()) {
|
|
for (SupCertEntity supCertEntity : supCertEntityList) {
|
|
if (supCertEntity.getName().equals(supCertSetEntity.getName())) {
|
|
if (StrUtil.isNotEmpty(supCertEntity.getFilePath())) {
|
|
iterable1.remove();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
String errMsg = "";
|
|
if (supCertSetEntities.size() > 0) {
|
|
return ResultVOUtils.error(500, "必传证书不齐全!");
|
|
}
|
|
}
|
|
String msg = "";
|
|
//查询是否包含审核未通过的证书
|
|
if (companyEntity.getAuditStatus() == ConstantStatus.AUDIT_PASS
|
|
|| companyEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE_PASS) {
|
|
FilterSupCertRequest filterSupCertRequest = new FilterSupCertRequest();
|
|
filterSupCertRequest.setAuditStatus(24);
|
|
filterSupCertRequest.setCustomerId(companyEntity.getCustomerId());
|
|
filterSupCertRequest.setType(ConstantStatus.CERT_COMPANY);
|
|
List<SupCertEntity> supCertEntityList = supCertService.filterCompanyCert(filterSupCertRequest);
|
|
if (CollUtil.isNotEmpty(supCertEntityList)) {
|
|
for (SupCertEntity supCertEntity : supCertEntityList) {
|
|
msg += supCertEntity.getName() + ",";
|
|
}
|
|
return ResultVOUtils.error(500, "审核失败,还有必须提交证书未确认(" + msg.substring(0, msg.length() - 1) + ")");
|
|
}
|
|
}
|
|
|
|
//修改用户角色
|
|
if (companyEntity.getRoleId() != null) {
|
|
CustomerInfoEntity customerInfoEntity = new CustomerInfoEntity();
|
|
customerInfoEntity.setCustomerId(Long.valueOf(companyEntity.getCustomerId()));
|
|
customerInfoEntity.setRoleId(companyEntity.getRoleId());
|
|
customerInfoEntity.setCompanyName(companyEntity.getCompanyName());
|
|
customerInfoEntity.setCustomerName(companyEntity.getCompanyName());
|
|
customerInfoService.updateCustomerInfo(customerInfoEntity);
|
|
//获取该供应商下面的用户
|
|
List<AuthAdmin> authAdmin = authAdminService.findByCustomerld(companyEntity.getCustomerId());
|
|
for (AuthAdmin obj : authAdmin) {
|
|
AuthRoleAdmin authRoleAdmin = new AuthRoleAdmin();
|
|
authRoleAdmin.setUser_id(obj.getId());
|
|
authRoleAdmin.setRole_id(Long.valueOf(companyEntity.getRoleId()));
|
|
authRoleAdminService.updateAuthRoleAdmin(authRoleAdmin);
|
|
}
|
|
}
|
|
|
|
|
|
AuthAdmin authAdmin = getUser();
|
|
companyEntity.setAuditor(authAdmin.getId() + "");
|
|
companyEntity.setAuditTime(new Date());
|
|
companyEntity.setUpdateTime(new Date());
|
|
boolean b = companyService.modifyCompany(companyEntity);
|
|
CustomerContactEntity customerContactEntity = new CustomerContactEntity();
|
|
customerContactEntity.setTel(companyEntity.getTel());
|
|
customerContactEntity.setMobile(companyEntity.getMobile());
|
|
customerContactEntity.setEmail(companyEntity.getEmail());
|
|
customerContactEntity.setContacts(companyEntity.getContacts());
|
|
customerContactEntity.setCustomerId(companyEntity.getCustomerId());
|
|
customerContactService.updateCustomerContact(customerContactEntity);
|
|
|
|
BasicCorpEntity basicCorpEntity = new BasicCorpEntity();
|
|
basicCorpEntity.setErpId(companyEntity.getCustomerId());
|
|
basicCorpEntity.setName(companyEntity.getCompanyName());
|
|
basicCorpEntity.setSpell(PinyinUtil.getFirstLetter(companyEntity.getCompanyName(), ""));
|
|
basicCorpEntity.setAddr(companyEntity.getArea() + companyEntity.getDetailAddr());
|
|
basicCorpEntity.setCreditNo(companyEntity.getCreditNum());
|
|
basicCorpEntity.setContact(companyEntity.getContacts());
|
|
basicCorpEntity.setMobile(companyEntity.getMobile());
|
|
basicCorpEntity.setCorpType(ConstantStatus.CORP_SP);
|
|
basicCorpEntity.setUpdateTime(new Date());
|
|
basicCorpService.insertBasicUnitMaintain(basicCorpEntity);
|
|
|
|
return ResultVOUtils.success("修改成功");
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("/sup/company/selectBind")
|
|
public BaseResponse selectBind(@RequestBody SelectCorpBindRequest selectCorpBindRequest) {
|
|
|
|
BasicCorpEntity basicCorpEntity = basicCorpService.selectByErpId(selectCorpBindRequest.getCustomerId());
|
|
SupCompanyEntity supCompanyEntity = new SupCompanyEntity();
|
|
supCompanyEntity.setCustomerId(basicCorpEntity.getErpId());
|
|
supCompanyEntity.setCompanyName(basicCorpEntity.getName());
|
|
supCompanyEntity.setCreditNum(basicCorpEntity.getCreditNo());
|
|
supCompanyEntity.setContacts(basicCorpEntity.getContact());
|
|
supCompanyEntity.setTel(basicCorpEntity.getMobile());
|
|
|
|
return ResultVOUtils.success(supCompanyEntity);
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
@PostMapping("api/pur/supCompany/delete")
|
|
public BaseResponse deleteSupCompany(@RequestBody DeleteRequest deleteRequest) {
|
|
boolean b = supCompanyService.deleteCompany(deleteRequest.getId());
|
|
if (b)
|
|
return ResultVOUtils.success("删除成功");
|
|
else {
|
|
return ResultVOUtils.error(500, "删除失败");
|
|
}
|
|
}
|
|
|
|
@AuthRuleAnnotation("")
|
|
@GetMapping("api/pur/supCompany/getRoId")
|
|
public BaseResponse getRoId(String companyId) {
|
|
CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(companyId);
|
|
|
|
return ResultVOUtils.success(customerInfoEntity);
|
|
}
|
|
|
|
|
|
public String getCustomerId() {
|
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
if (attributes == null) {
|
|
throw new JsonException(ResultEnum.NOT_NETWORK);
|
|
}
|
|
HttpServletRequest request = attributes.getRequest();
|
|
String userId = request.getHeader("ADMIN_ID");
|
|
AuthAdmin authAdmin = authAdminService.findById(Long.parseLong(userId));
|
|
return authAdmin.getCustomerId() + "";
|
|
}
|
|
|
|
public AuthAdmin getUser() {
|
|
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
if (attributes == null) {
|
|
throw new JsonException(ResultEnum.NOT_NETWORK);
|
|
}
|
|
HttpServletRequest request = attributes.getRequest();
|
|
String userId = request.getHeader("ADMIN_ID");
|
|
AuthAdmin authAdmin = authAdminService.findById(Long.parseLong(userId));
|
|
return authAdmin;
|
|
}
|
|
}
|