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/basic/UdiRlSupController.java

355 lines
18 KiB
Java

2 years ago
package com.glxp.api.controller.basic;
import cn.hutool.core.bean.BeanUtil;
2 years ago
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
2 years ago
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
2 years ago
import com.glxp.api.annotation.Log;
2 years ago
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
2 years ago
import com.glxp.api.constant.BusinessType;
import com.glxp.api.constant.SocketMsgType;
2 years ago
import com.glxp.api.controller.BaseController;
import com.glxp.api.controller.sync.SpsSyncWebSocket;
2 years ago
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.basic.*;
import com.glxp.api.entity.sync.SocketMsgEntity;
2 years ago
import com.glxp.api.entity.system.CompanyEntity;
2 years ago
import com.glxp.api.exception.JsonException;
import com.glxp.api.req.basic.*;
2 years ago
import com.glxp.api.req.system.CompanyRequest;
import com.glxp.api.req.system.DeleteCompanyFileRequest;
import com.glxp.api.res.PageSimpleResponse;
2 years ago
import com.glxp.api.res.basic.CompanyProductRelevanceResponse;
2 years ago
import com.glxp.api.res.basic.UdiRlSupResponse;
import com.glxp.api.res.basic.UdiRelevanceResponse;
import com.glxp.api.service.auth.AuthAdminService;
import com.glxp.api.service.auth.CustomerInfoService;
2 years ago
import com.glxp.api.service.basic.*;
import com.glxp.api.service.system.ClassifyCodeService;
2 years ago
import com.glxp.api.service.system.CompanyService;
import com.glxp.api.util.IntUtil;
2 years ago
import com.glxp.api.util.SupplementVailUtil;
2 years ago
import com.glxp.api.util.udi.FilterUdiUtils;
2 years ago
import org.springframework.beans.BeanUtils;
2 years ago
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 org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
2 years ago
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
*
*/
@RestController
2 years ago
public class UdiRlSupController extends BaseController {
2 years ago
@Resource
private AuthAdminService authAdminService;
@Resource
private UdiRlSupService udiRlSupService;
@Resource
private CompanyProductsRelService companyProductsRelService;
@Resource
private BasicCorpService basicUnitMaintainService;
@Resource
private UdiRelevanceService udiRelevanceService;
2 years ago
@Resource
private CompanyService companyService;
@Resource
private CompanyProductRelevanceService companyProductRelevanceService;
@Resource
private SupplementVailUtil supplementVailUtil;
2 years ago
@Resource
private UdiProductService udiProductService;
@Resource
SpsSyncWebSocket webSocketServer;
@Resource
private CustomerInfoService customerInfoService;
@Resource
private IBasicBussinessTypeService basicBussinessTypeService;
@Resource
private com.glxp.api.service.system.ClassifyCodeService classifyCodeService;
2 years ago
@AuthRuleAnnotation("")
@GetMapping("/sale/info/company/product/relevance/filter")
public BaseResponse filterCompanyProductRelevance(CompanyProductRelevanceRequest companyProductRelevanceRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
2 years ago
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getCustomerId())) {
String customerId = getCustomerId();
if (customerId.equals("110")) {
companyProductRelevanceRequest.setCustomerId(null);
}
}
if (ObjectUtil.isNotNull(companyProductRelevanceRequest.getUserFlag())) {
Integer userFlag = companyProductRelevanceRequest.getUserFlag();
//获取 供应商状态为 userFlag 的 customerIds列表
List<Long> customerIds = customerInfoService.selectCustomerIdListByUserFlag(userFlag);
companyProductRelevanceRequest.setCustomerIds(customerIds);
}
2 years ago
companyProductRelevanceRequest.setIsDisable(false);
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getUdiCode())) {
UdiEntity udiEntity = FilterUdiUtils.getUdi(companyProductRelevanceRequest.getUdiCode());
if (udiEntity != null) {
companyProductRelevanceRequest.setNameCode(udiEntity.getUdi());
companyProductRelevanceRequest.setUnionCode(udiEntity.getUdi());
}
}
//如果输入DI标识精确找到不同层级对应的产品信息
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getUnionCode())) {
FilterUdiRelRequest filterUdiInfoRequest = new FilterUdiRelRequest();
filterUdiInfoRequest.setNameCode(companyProductRelevanceRequest.getUnionCode());
List<UdiRelevanceResponse> temps = udiRelevanceService.filterUdiGp(filterUdiInfoRequest);
if (temps != null && temps.size() > 0) {
2 years ago
companyProductRelevanceRequest.setOriginUuid(temps.get(0).getOriginUuid());
2 years ago
companyProductRelevanceRequest.setNameCode(filterUdiInfoRequest.getNameCode());
companyProductRelevanceRequest.setUnionCode(null);
}
} else {
//只查找主标识产品信息
companyProductRelevanceRequest.setDiType(1);
}
//校验是否需要扫码
if (StrUtil.isNotEmpty(companyProductRelevanceRequest.getAction())) {
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(companyProductRelevanceRequest.getAction());
//是否校验产品采购类型 1校验2.无需校验
if (IntUtil.value(bussinessTypeEntity.getVailProductAttributes()) == 1) {
companyProductRelevanceRequest.setPurType(IntUtil.value(bussinessTypeEntity.getActionType()));
}
//是否开启校验扫码 0:不校验1:只允许录入扫码产品2:只允许录入不扫码产品
if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 1) {
companyProductRelevanceRequest.setCodeCheck(1);
} else if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 2) {
companyProductRelevanceRequest.setCodeCheck(0);
} else {
companyProductRelevanceRequest.setCodeCheck(null);
}
}
2 years ago
List<UdiRlSupResponse> basicInstrumentMaintainRelevanceResponses = null;
basicInstrumentMaintainRelevanceResponses = udiRlSupService.filterUdiGp(companyProductRelevanceRequest);
PageInfo<UdiRlSupResponse> pageInfo;
pageInfo = new PageInfo<>(basicInstrumentMaintainRelevanceResponses);
PageSimpleResponse<UdiRlSupResponse> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(basicInstrumentMaintainRelevanceResponses);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("/sale/info/company/product/corp/filter")
public BaseResponse filterRlCorp(FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
if (StrUtil.isEmpty(filterCompanyProductRelevanceRequest.getUdiRlIdFk())) {
return ResultVOUtils.error(500, "请先选择产品!");
}
List<UdiRlSupEntity> companyProductRelevanceEntities =
udiRlSupService.filterCompanyProductRelevance(filterCompanyProductRelevanceRequest);
if (!companyProductRelevanceEntities.isEmpty()) {
List<String> erpIds = new ArrayList<>();
for (UdiRlSupEntity udiRlSupEntity : companyProductRelevanceEntities) {
//过滤,如果默认已经有供应商了,则查出对应供应商即可
if (StrUtil.isNotEmpty(filterCompanyProductRelevanceRequest.getUnitFk())) {
if (udiRlSupEntity.getUnitFk().equals(filterCompanyProductRelevanceRequest.getUnitFk())) {
erpIds.add(udiRlSupEntity.getUnitFk());
}
} else {
erpIds.add(udiRlSupEntity.getUnitFk());
}
}
if (CollUtil.isEmpty(erpIds)) {
return ResultVOUtils.error(500, "该产品未关联供应商");
}
List<BasicCorpEntity> basicUnitMaintainEntities = basicUnitMaintainService.batchSelectByErpIdsAndName(erpIds, filterCompanyProductRelevanceRequest.getKey());
return ResultVOUtils.success(basicUnitMaintainEntities);
}
return ResultVOUtils.error(500, "该产品未关联供应商!");
}
@AuthRuleAnnotation("")
@GetMapping("/spms/info/company/product/filterAll")
public BaseResponse filterAll(FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
List<UdiRlSupEntity> companyProductRelevanceEntities =
udiRlSupService.filterCompanyProductRelevance(filterCompanyProductRelevanceRequest);
PageInfo<UdiRlSupEntity> pageInfo;
pageInfo = new PageInfo<>(companyProductRelevanceEntities);
PageSimpleResponse<UdiRlSupEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(companyProductRelevanceEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@GetMapping("/sale/info/companyProductRelevance")
public BaseResponse getCompanyProductRelevanceInfo(CompanyRequest companyRequest) {
UdiRlSupEntity udiRlSupEntity = udiRlSupService.findCompanyProductRelevance(companyRequest.getCustomerId());
if (udiRlSupEntity != null) {
return ResultVOUtils.success(udiRlSupEntity);
}
return ResultVOUtils.error(500, "空");
}
@AuthRuleAnnotation("")
@GetMapping("/sale/info/getCompanyProductRelevance")
public BaseResponse getCompanyProductRelevance(FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest) {
List<UdiRlSupEntity> companyProductRelevanceEntities = udiRlSupService.getCompanyProductRelevance(filterCompanyProductRelevanceRequest);
PageInfo<UdiRlSupEntity> pageInfo = new PageInfo<>(companyProductRelevanceEntities);
PageSimpleResponse<UdiRlSupEntity> pageSimpleResponse = new PageSimpleResponse<>();
pageSimpleResponse.setTotal(pageInfo.getTotal());
pageSimpleResponse.setList(companyProductRelevanceEntities);
return ResultVOUtils.success(pageSimpleResponse);
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/insertCompanyProductRelevance")
2 years ago
@Log(title = "单据管理", businessType = BusinessType.INSERT)
2 years ago
public BaseResponse insertCompanyProductRelevance(@RequestBody UdiRlSupEntity udiRlSupEntity) {
if (udiRlSupService.findCompanyProductRelevanceByProductUuid(udiRlSupEntity) != null) {
return ResultVOUtils.error(ResultEnum.DATA_REPEAT);
}
udiRlSupEntity.setUnitFk(null);
udiRlSupEntity.setCreateTime(new Date());
udiRlSupEntity.setUpdateTime(new Date());
udiRlSupEntity.setAuditStatus("3");
boolean b = udiRlSupService.insertCompanyProductRelevance(udiRlSupEntity);
return ResultVOUtils.success("成功");
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/insertFilter")
2 years ago
@Log(title = "单据管理", businessType = BusinessType.INSERT)
2 years ago
public BaseResponse insertFilter(@RequestBody UdiInfoExportRequest udiInfoExportRequest) {
CompanyEntity companyEntity = companyService.findCompany(udiInfoExportRequest.getCustomerId() + "");
if (companyEntity != null) {
if ("110".equals(companyEntity.getUnitIdFk())) {
udiInfoExportRequest.setUnitFk(null);
} else {
udiInfoExportRequest.setUnitFk(companyEntity.getUnitIdFk());
}
2 years ago
}
2 years ago
//查询本企业有没有选择该产品有选择不能选择
CompanyProductRelevanceRequest companyProductRelevanceRequest = new CompanyProductRelevanceRequest();
companyProductRelevanceRequest.setCustomerId(udiInfoExportRequest.getCustomerId() + "");
2 years ago
List<CompanyProductRelevanceResponse> basicInstrumentMaintainRelevanceResponses = null;
companyProductRelevanceRequest.setDiType(1);
basicInstrumentMaintainRelevanceResponses = companyProductRelevanceService.filterUdiGp(companyProductRelevanceRequest);
String rlidStr = udiInfoExportRequest.getRlIds().get(0);
for (CompanyProductRelevanceResponse obj : basicInstrumentMaintainRelevanceResponses) {
String rlid = String.valueOf(obj.getRlId());
if (rlid.equals(rlidStr)) {
return ResultVOUtils.error(999, "该企业已选择该产品,请勿重复选择!");
}
2 years ago
}
2 years ago
String vailResult = supplementVailUtil.vail(udiInfoExportRequest.getSupplementRequest(), SupplementVailUtil.SUP_SELECT);
if (vailResult != null)
return ResultVOUtils.error(500, vailResult);
2 years ago
companyProductsRelService.insertCompanyProducts(udiInfoExportRequest);
UdiRelevanceEntity udiRelevanceEntity = new UdiRelevanceEntity();
udiRelevanceEntity.setId(Long.parseLong(rlidStr));
udiRelevanceEntity.setLockStatus(1);
1 year ago
udiRelevanceEntity.setGroupBuy(udiInfoExportRequest.getSupplementRequest().getGroupBuy());
udiRelevanceEntity.setUpdateTime(new Date());
udiRelevanceService.updateUdiRelevance(udiRelevanceEntity);
2 years ago
UdiProductEntity udiProductEntity = new UdiProductEntity();
BeanUtil.copyProperties(udiInfoExportRequest.getSupplementRequest(), udiProductEntity);
//处理是否需要扫码字段
classifyCodeService.updateRequireScanCode(udiProductEntity);
udiProductEntity.setUpdateTime(new Date());
UdiRelevanceEntity udiRelevanceEntity1 = udiRelevanceService.selectById(Long.valueOf(rlidStr));
UdiProductEntity byUuid = udiProductService.findByUuid(udiRelevanceEntity1.getUuid());
if (byUuid != null) {
byUuid.setCatalogname1(udiProductEntity.getCatalogname1());
byUuid.setCatalogname2(udiProductEntity.getCatalogname2());
byUuid.setCatalogname3(udiProductEntity.getCatalogname3());
byUuid.setYbbm(udiProductEntity.getYbbm());
byUuid.setManufactory(udiProductEntity.getManufactory());
byUuid.setUpdateTime(new Date());
udiProductService.updateUdiInfo(byUuid);
} else {
udiProductEntity.setId(IdUtil.getSnowflakeNextId());
udiProductService.insertUdiInfo(udiProductEntity);
}
// udiProductEntity.setId(IdUtil.getSnowflakeNextId());
// udiProductService.insertUdiInfo(udiProductEntity);
return ResultVOUtils.success("选入成功!");
2 years ago
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/updateCompanyProductRelevance")
2 years ago
@Log(title = "单据管理", businessType = BusinessType.UPDATE)
2 years ago
public BaseResponse updateCompanyProductRelevance(@RequestBody UdiRlSupEntity udiRlSupEntity) {
udiRlSupEntity.setUpdateTime(new Date());
int b = udiRlSupService.updateCompanyProductRelevance(udiRlSupEntity);
return ResultVOUtils.success("修改成功");
}
@PostMapping("/sale/info/deleteCompanyProductRelevance")
2 years ago
@Log(title = "单据管理", businessType = BusinessType.DELETE)
public BaseResponse deleteCompanyProductRelevance(@RequestBody DeleteCompanyFileRequest deleteCompanyFileRequest) {
2 years ago
boolean b = udiRlSupService.deleteById(deleteCompanyFileRequest.getId());
//推送
BasicDataRequest basicDataRequest = new BasicDataRequest();
basicDataRequest.setDeleteCompanyFileRequest(deleteCompanyFileRequest);
basicDataRequest.setKey("BASIC_MANAGE");
Long userId = getUserId();
BasicDataRequest request = webSocketServer.insert(basicDataRequest, userId + "");
request.setDeleteCompanyFileRequest(deleteCompanyFileRequest);
webSocketServer.sendMessage(SocketMsgEntity.builder().type(SocketMsgType.BASIC_MANAGE_DELETE).content(request).remark("入院物资维护").build(), null);
2 years ago
return ResultVOUtils.success("成功");
}
@AuthRuleAnnotation("")
@PostMapping("/sale/info/company/product/relevance/copyCustomerId")
public BaseResponse copyCustomerId(@RequestBody @Valid CopyCustomerIdRequest copyCustomerIdRequest,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
companyProductRelevanceService.copyCustomerId(copyCustomerIdRequest);
return ResultVOUtils.success("转让成功");
}
2 years ago
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() + "";
}
}