| | |
| | | import com.baomidou.mybatisplus.mapper.Wrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.param.BasDevpInitParam; |
| | | import com.zy.asrs.service.BasCrnpService; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.web.BaseController; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.BaseRes; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.core.exception.CoolException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.nio.charset.Charset; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | public class BasDevpController extends BaseController { |
| | | |
| | | private static final Charset SQL_SERVER_VARCHAR_CHARSET = Charset.forName("GBK"); |
| | | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | |
| | | @RequestMapping(value = "/basDevp/init/auth") |
| | | @ManagerAuth(memo = "初始化站点") |
| | | public R init(BasDevpInitParam param) { |
| | | List<BasDevp> list = new ArrayList<>(); |
| | | for (int devNo = param.getStartDev() ; devNo<=param.getEndDev() ; devNo++){ |
| | | BasDevp basDevp = basDevpService.selectById(devNo); |
| | | if (Cools.isEmpty(basDevp)){ |
| | | BasDevp basDevp1 = new BasDevp(); |
| | | basDevp1.setDevNo(devNo); |
| | | basDevp1.setInEnable("Y"); |
| | | basDevp1.setOutEnable("Y"); |
| | | basDevp1.setAutoing("Y"); |
| | | basDevp1.setLoading("Y"); |
| | | basDevp1.setCanining("Y"); |
| | | basDevp1.setCanouting("Y"); |
| | | basDevp1.setModiUser(getUserId()); |
| | | basDevp1.setModiTime(new Date()); |
| | | list.add(basDevp1); |
| | | } |
| | | } |
| | | basDevpService.insertBatch(list); |
| | | return R.ok("初始化成功"); |
| | | } |
| | | |
| | | @RequestMapping(value = "/basDevp/{id}/auth") |
| | | @ManagerAuth |
| | |
| | | return R.ok(basDevpService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private void convert(Map<String, Object> map, EntityWrapper wrapper){ |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | if (entry.getKey().endsWith(">")) { |
| | | wrapper.ge(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); |
| | | } else if (entry.getKey().endsWith("<")) { |
| | | wrapper.le(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); |
| | | String val = String.valueOf(entry.getValue()); |
| | | if (val.contains(RANGE_TIME_LINK)){ |
| | | String[] dates = val.split(RANGE_TIME_LINK); |
| | | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | | } else { |
| | | wrapper.eq(entry.getKey(), String.valueOf(entry.getValue())); |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | |
| | | @RequestMapping(value = "/basDevp/add/auth") |
| | | @ManagerAuth(memo = "站点添加") |
| | | public R add(BasDevp basDevp) { |
| | | normalizeInboundPriority(basDevp, null); |
| | | normalizeAndValidateForSave(basDevp); |
| | | basDevp.setModiUser(getUserId()); |
| | | basDevp.setModiTime(new Date()); |
| | | basDevp.setAppeUser(getUserId()); |
| | |
| | | if (Cools.isEmpty(basDevp) || null==basDevp.getDevNo()){ |
| | | return R.error(); |
| | | } |
| | | BasDevp existing = basDevpService.selectById(basDevp.getDevNo()); |
| | | if (existing == null) { |
| | | return R.error("站点不存在"); |
| | | } |
| | | normalizeInboundPriority(basDevp, existing); |
| | | normalizeAndValidateForSave(basDevp); |
| | | basDevp.setModiUser(getUserId()); |
| | | basDevp.setModiTime(new Date()); |
| | | basDevpService.updateById(basDevp); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | private void normalizeAndValidateForSave(BasDevp basDevp) { |
| | | if (basDevp == null) { |
| | | return; |
| | | } |
| | | basDevp.setInEnable(normalizeYn("可入", basDevp.getInEnable())); |
| | | basDevp.setOutEnable(normalizeYn("可出", basDevp.getOutEnable())); |
| | | basDevp.setAutoing(normalizeYn("自动", basDevp.getAutoing())); |
| | | basDevp.setLoading(normalizeYn("有物", basDevp.getLoading())); |
| | | basDevp.setCanining(normalizeYn("能入", basDevp.getCanining())); |
| | | basDevp.setCanouting(normalizeYn("能出", basDevp.getCanouting())); |
| | | basDevp.setFronting(normalizeYn("fronting", basDevp.getFronting())); |
| | | basDevp.setRearing(normalizeYn("rearing", basDevp.getRearing())); |
| | | basDevp.setUping(normalizeYn("uping", basDevp.getUping())); |
| | | basDevp.setDowning(normalizeYn("downing", basDevp.getDowning())); |
| | | basDevp.setInreq1(normalizeYn("需求1", basDevp.getInreq1())); |
| | | basDevp.setInreq2(normalizeYn("需求2", basDevp.getInreq2())); |
| | | basDevp.setInOk(normalizeYn("in_ok", basDevp.getInOk())); |
| | | basDevp.setOutOk(normalizeYn("out_ok", basDevp.getOutOk())); |
| | | |
| | | validateVarcharLength("设备描述", basDevp.getDecDesc(), 30); |
| | | validateVarcharLength("备注", basDevp.getDevMk(), 1); |
| | | validateVarcharLength("条形码", basDevp.getBarcode(), 255); |
| | | validateVarcharLength("绑定库区", basDevp.getArea(), 255); |
| | | validateVarcharLength("第一优先池", basDevp.getInFirstCrnCsv(), 255); |
| | | validateVarcharLength("第二优先池", basDevp.getInSecondCrnCsv(), 255); |
| | | } |
| | | |
| | | private String normalizeYn(String label, String value) { |
| | | if (Cools.isEmpty(value)) { |
| | | return null; |
| | | } |
| | | String normalized = value.trim().toUpperCase(Locale.ROOT); |
| | | if ("Y".equals(normalized) || "1".equals(normalized) || "TRUE".equals(normalized) || "YES".equals(normalized)) { |
| | | return "Y"; |
| | | } |
| | | if ("N".equals(normalized) || "0".equals(normalized) || "FALSE".equals(normalized) || "NO".equals(normalized) || "OFF".equals(normalized) || "ON".equals(normalized)) { |
| | | return "N"; |
| | | } |
| | | throw new CoolException(label + "只能为Y或N"); |
| | | } |
| | | |
| | | private void validateVarcharLength(String label, String value, int maxBytes) { |
| | | if (value == null) { |
| | | return; |
| | | } |
| | | int bytes = value.getBytes(SQL_SERVER_VARCHAR_CHARSET).length; |
| | | if (bytes > maxBytes) { |
| | | throw new CoolException(label + "长度不能超过" + maxBytes + "字节"); |
| | | } |
| | | } |
| | | |
| | | private void normalizeInboundPriority(BasDevp basDevp, BasDevp existing) { |
| | | if (basDevp == null) { |
| | | return; |
| | | } |
| | | String firstCsv = resolveCsvValue(basDevp.getInFirstCrnCsv(), existing == null ? null : existing.getInFirstCrnCsv()); |
| | | String secondCsv = resolveCsvValue(basDevp.getInSecondCrnCsv(), existing == null ? null : existing.getInSecondCrnCsv()); |
| | | |
| | | List<Integer> firstCrnNos = parseCrnPool("第一优先池", firstCsv); |
| | | List<Integer> secondCrnNos = parseCrnPool("第二优先池", secondCsv); |
| | | Set<Integer> duplicateCrnNos = new LinkedHashSet<>(firstCrnNos); |
| | | duplicateCrnNos.retainAll(secondCrnNos); |
| | | if (!duplicateCrnNos.isEmpty()) { |
| | | throw new CoolException("第一优先池和第二优先池不能重复配置同一台堆垛机:" + duplicateCrnNos); |
| | | } |
| | | |
| | | basDevp.setInFirstCrnCsv(Utils.normalizeCrnCsv(firstCrnNos)); |
| | | basDevp.setInSecondCrnCsv(Utils.normalizeCrnCsv(secondCrnNos)); |
| | | |
| | | if (existing == null) { |
| | | basDevp.setInFirstCrnCurrentNo(null); |
| | | basDevp.setInSecondCrnCurrentNo(null); |
| | | return; |
| | | } |
| | | |
| | | basDevp.setInFirstCrnCurrentNo(resolveCurrentNo(existing.getInFirstCrnCurrentNo(), firstCrnNos)); |
| | | basDevp.setInSecondCrnCurrentNo(resolveCurrentNo(existing.getInSecondCrnCurrentNo(), secondCrnNos)); |
| | | } |
| | | |
| | | private String resolveCsvValue(String incoming, String existing) { |
| | | if (incoming == null) { |
| | | return existing; |
| | | } |
| | | return incoming; |
| | | } |
| | | |
| | | private List<Integer> parseCrnPool(String label, String csv) { |
| | | List<Integer> crnNos; |
| | | try { |
| | | crnNos = Utils.parseCrnNos(csv); |
| | | } catch (CoolException e) { |
| | | throw new CoolException(label + e.getMessage()); |
| | | } |
| | | List<Integer> distinctCrnNos = Utils.distinctCrnNos(crnNos); |
| | | if (crnNos.size() != distinctCrnNos.size()) { |
| | | throw new CoolException(label + "存在重复堆垛机号"); |
| | | } |
| | | for (Integer crnNo : distinctCrnNos) { |
| | | if (basCrnpService.selectById(crnNo) == null) { |
| | | throw new CoolException(label + "包含不存在的堆垛机号:" + crnNo); |
| | | } |
| | | } |
| | | return distinctCrnNos; |
| | | } |
| | | |
| | | private Integer resolveCurrentNo(Integer currentNo, List<Integer> crnNos) { |
| | | if (currentNo == null || Cools.isEmpty(crnNos) || !crnNos.contains(currentNo)) { |
| | | return null; |
| | | } |
| | | return currentNo; |
| | | } |
| | | |
| | | } |