|  |  | 
 |  |  | import com.vincent.rsf.server.manager.entity.Companys; | 
 |  |  | import com.vincent.rsf.server.manager.entity.Warehouse; | 
 |  |  | import com.vincent.rsf.server.manager.service.CompanysService; | 
 |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
 |  |  | import com.vincent.rsf.server.system.controller.BaseController; | 
 |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
 |  |  | import io.swagger.annotations.Api; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  | 
 |  |  |  | 
 |  |  |         companys.setCreateBy(getLoginUserId()); | 
 |  |  |         companys.setUpdateBy(getLoginUserId()); | 
 |  |  |         if (StringUtils.isBlank(companys.getCode())) { | 
 |  |  |             String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_COMPANYS_CODE, companys); | 
 |  |  |             if (StringUtils.isBlank(ruleCode)) { | 
 |  |  |                 throw new CoolException("编码规则错误:请检查「SYS_COMPANYS_CODE」是否设置完成!!"); | 
 |  |  |             } | 
 |  |  |             companys.setCode(ruleCode); | 
 |  |  |         } | 
 |  |  |         if (!companysService.save(companys)) { | 
 |  |  |             return R.error("Save Fail"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |     @OperationLog("Update 字典数据集") | 
 |  |  |     @PostMapping("/companys/update") | 
 |  |  |     public R update(@RequestBody Companys companys) { | 
 |  |  |         companys.setUpdateBy(getLoginUserId()); | 
 |  |  |         if (Objects.isNull(companys.getName())) { | 
 |  |  |             throw new CoolException("名称不能为空!!"); | 
 |  |  |         } | 
 |  |  | 
 |  |  |         if (Objects.isNull(companys.getType())) { | 
 |  |  |             throw new CoolException("类型不能为空!!"); | 
 |  |  |         } | 
 |  |  | //        Companys companys1 = companysService.getById(companys.getId()); | 
 |  |  |         List<Companys> warehouses = companysService.list(new LambdaQueryWrapper<Companys>() | 
 |  |  |                 .eq(Companys::getName, companys.getName()) | 
 |  |  |                 .eq(Companys::getType, companys.getType()) | 
 |  |  |                 .eq(Companys::getBreifCode, companys.getBreifCode())); | 
 |  |  |         if (!warehouses.isEmpty()) { | 
 |  |  |             throw new CoolException("企业已存在!!"); | 
 |  |  |         } | 
 |  |  |         if (!companysService.list(new LambdaQueryWrapper<Companys>() | 
 |  |  |                 .eq(Companys::getType, companys.getType()) | 
 |  |  |                 .eq(Companys::getName, companys.getName()) | 
 |  |  |                 .eq(Companys::getCode, companys.getBreifCode())).isEmpty()) { | 
 |  |  |             throw new CoolException("企业编码重复!!"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         companys.setUpdateTime(null); | 
 |  |  |         companys.setUpdateBy(getLoginUserId()); | 
 |  |  |         if (!companysService.updateById(companys)) { | 
 |  |  |             return R.error("Update Fail"); | 
 |  |  |         } |