|
|
|
|
@ -138,206 +138,22 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> |
|
|
|
|
// 送检单位、采样单位之类的,如果没有就新增
|
|
|
|
|
addIfNull(entrust); |
|
|
|
|
|
|
|
|
|
// 样品关联表入库
|
|
|
|
|
List<SimpleRel> rels = new ArrayList<>(); |
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
|
|
|
|
|
String month1 = fullByZero(now.getMonthValue()); |
|
|
|
|
String day1 = fullByZero(now.getDayOfMonth()); |
|
|
|
|
String hour1 = fullByZero(now.getHour()); |
|
|
|
|
|
|
|
|
|
// 检测编号前缀
|
|
|
|
|
String[] strings = entrust.getAcceptanceNum().split("-"); |
|
|
|
|
String s = strings[1] + now.getYear() + month1 + day1 + hour1 + "-"; |
|
|
|
|
|
|
|
|
|
StringBuilder simpleName = new StringBuilder(); |
|
|
|
|
Integer simpleCount = 0; |
|
|
|
|
List<Map<String, Object>> list = entrust.getSimpleNames(); |
|
|
|
|
// 样品关联数据入库
|
|
|
|
|
entrust = addSimpleRel(entrust, id); |
|
|
|
|
|
|
|
|
|
// 样品排序
|
|
|
|
|
int sort = 1; |
|
|
|
|
for (Map<String, Object> map : list) { |
|
|
|
|
// 样品名称
|
|
|
|
|
String name = (String) map.get("simpleName"); |
|
|
|
|
simpleName.append(name).append(","); |
|
|
|
|
// 样品数量
|
|
|
|
|
Integer count = (Integer) map.get("simpleCount"); |
|
|
|
|
simpleCount += count; |
|
|
|
|
// 原始编号
|
|
|
|
|
String num = (String) map.get("originalNum"); |
|
|
|
|
String[] split = num.split("-"); |
|
|
|
|
int a = Integer.parseInt(split[0]); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
|
SimpleRel simpleRel = new SimpleRel(); |
|
|
|
|
if (entrust.getId() != null) { |
|
|
|
|
simpleRel.setEntrustId(entrust.getId()); |
|
|
|
|
} else { |
|
|
|
|
simpleRel.setEntrustId(id); |
|
|
|
|
} |
|
|
|
|
simpleRel.setSimpleName(name); |
|
|
|
|
simpleRel.setReagentNum(1); |
|
|
|
|
simpleRel.setReagentExperieNum(s + ((a - 1) * 2 + i + 1 + count)); |
|
|
|
|
simpleRel.setExamineNum(1); |
|
|
|
|
simpleRel.setExamineExperieNum(s + ((a - 1) * 2 + i + 1)); |
|
|
|
|
simpleRel.setRecessiveNum((i + a) + ""); |
|
|
|
|
simpleRel.setOriginalNum((i + a) + ""); |
|
|
|
|
simpleRel.setStatus(0); |
|
|
|
|
simpleRel.setSort(sort); |
|
|
|
|
rels.add(simpleRel); |
|
|
|
|
} |
|
|
|
|
sort++; |
|
|
|
|
} |
|
|
|
|
simpleRelService.saveBatch(rels); |
|
|
|
|
// 是否为合同新增委托单
|
|
|
|
|
entrust = isContractTypeEntrust(entrust); |
|
|
|
|
|
|
|
|
|
// 委托单入库/修改
|
|
|
|
|
if (entrust.getSampleReceiverId() != null) { |
|
|
|
|
R<User> userR = userClient.userInfoById(Long.valueOf(entrust.getSampleReceiverId())); |
|
|
|
|
User data = userR.getData(); |
|
|
|
|
if (data != null) { |
|
|
|
|
entrust.setSampleReceiverName(data.getName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
entrust.setSimpleName(simpleName.toString()); |
|
|
|
|
entrust.setSimpleCount(simpleCount); |
|
|
|
|
String originalNum = ""; |
|
|
|
|
if (simpleCount > 9) { |
|
|
|
|
originalNum = "01-" + simpleCount; |
|
|
|
|
} else { |
|
|
|
|
originalNum = "01-0" + simpleCount; |
|
|
|
|
} |
|
|
|
|
String s1 = JSON.toJSONString(entrust.getSimpleNames()); |
|
|
|
|
entrust.setSimpleJson(s1); |
|
|
|
|
entrust.setOriginalNum(originalNum); |
|
|
|
|
entrust.setIsDeleted(0); |
|
|
|
|
entrust.setCreateUser(null); |
|
|
|
|
entrust.setCreateTime(new Date()); |
|
|
|
|
entrust.setUpdateTime(new Date()); |
|
|
|
|
entrust.setUpdateUser(null); |
|
|
|
|
entrust.setEntrustStatus("1"); |
|
|
|
|
// 是否为合同新增委托单
|
|
|
|
|
if (entrust.getContractId() != null) { |
|
|
|
|
entrust.setEntrustType(2); |
|
|
|
|
Contract contract = new Contract(); |
|
|
|
|
contract.setId(entrust.getContractId()); |
|
|
|
|
contract.setStatus(2); |
|
|
|
|
contractService.updateById(contract); |
|
|
|
|
} else { |
|
|
|
|
entrust.setEntrustType(1); |
|
|
|
|
} |
|
|
|
|
addOrUpdateEntrust(entrust, id); |
|
|
|
|
|
|
|
|
|
if (entrust.getId() != null) { |
|
|
|
|
this.updateById(entrust); |
|
|
|
|
} else { |
|
|
|
|
entrust.setId(id); |
|
|
|
|
this.save(entrust); |
|
|
|
|
} |
|
|
|
|
// 新增或修改 检测集合
|
|
|
|
|
addOrUpdateExamines(entrust.getExamines(), entrust.getId()); |
|
|
|
|
return entrust; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 如果有就取用,没有就新增 |
|
|
|
|
* 有共同点,待抽 |
|
|
|
|
*/ |
|
|
|
|
private void addIfNull(Entrust entrust) { |
|
|
|
|
// 送检单位
|
|
|
|
|
EntrustCustomer byId = customerService.getById(entrust.getEntrustCustomerId()); |
|
|
|
|
if (byId != null) { |
|
|
|
|
entrust.setEntrustCustomerName(byId.getName()); |
|
|
|
|
} else { |
|
|
|
|
EntrustCustomer customer = new EntrustCustomer(); |
|
|
|
|
customer.setStatus(1); |
|
|
|
|
customer.setPhone(entrust.getPhone()); |
|
|
|
|
customer.setId(RandomUtils.nextLong()); |
|
|
|
|
customer.setFax(entrust.getFacsimile()); |
|
|
|
|
customer.setEmail(entrust.getPostalCode()); |
|
|
|
|
customer.setFullName(entrust.getSubmittedBy()); |
|
|
|
|
customer.setName(entrust.getEntrustCustomerName()); |
|
|
|
|
customerService.save(customer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 采样单位
|
|
|
|
|
EntrustCustomer byId1 = customerService.getById(entrust.getTakeCompanyId()); |
|
|
|
|
if (byId1 != null) { |
|
|
|
|
entrust.setTakeCompany(byId1.getName()); |
|
|
|
|
} else { |
|
|
|
|
EntrustCustomer customer = new EntrustCustomer(); |
|
|
|
|
customer.setStatus(2); |
|
|
|
|
customer.setId(RandomUtils.nextLong()); |
|
|
|
|
customer.setPhone(entrust.getTakePhone()); |
|
|
|
|
customer.setName(entrust.getTakeCompany()); |
|
|
|
|
customer.setFullName(entrust.getTakePerson()); |
|
|
|
|
customer.setAddress(entrust.getTakeCompanyAddress()); |
|
|
|
|
customerService.save(customer); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增或修改检验集合 |
|
|
|
|
*/ |
|
|
|
|
private void addOrUpdateExamines(List<Examine> examines, Long entrustId) { |
|
|
|
|
if (CollectionUtils.isNotEmpty(examines)) { |
|
|
|
|
List<Examine> saveList = new ArrayList<>(); |
|
|
|
|
List<Examine> updateList = new ArrayList<>(); |
|
|
|
|
for (int i = 0; i < examines.size(); i++) { |
|
|
|
|
Examine examine = examines.get(i); |
|
|
|
|
if (examine.getId() != null) { |
|
|
|
|
updateList.add(examine); |
|
|
|
|
} else { |
|
|
|
|
examine.setStatus(0); |
|
|
|
|
examine.setIsDeleted(0); |
|
|
|
|
examine.setSimpleCount(0); |
|
|
|
|
examine.setExperieNum(""); |
|
|
|
|
examine.setExamineOrder(i + 1); |
|
|
|
|
examine.setEntrustId(entrustId); |
|
|
|
|
examine.setCreateTime(new Date()); |
|
|
|
|
examine.setUpdateTime(new Date()); |
|
|
|
|
saveList.add(examine); |
|
|
|
|
} |
|
|
|
|
// 使用次数 +1 操作
|
|
|
|
|
addUseCount(1, examine.getExamineItemId()); |
|
|
|
|
addUseCount(2, examine.getExamineWayId()); |
|
|
|
|
addUseCount(3, examine.getExamineBasisId()); |
|
|
|
|
} |
|
|
|
|
examineService.saveBatch(saveList); |
|
|
|
|
examineService.updateBatchById(updateList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addUseCount(int type, Long elementId) { |
|
|
|
|
if (elementId == null) { return; } |
|
|
|
|
if (type == 1) { |
|
|
|
|
ExamineItem examineItem = examineItemService.getById(elementId); |
|
|
|
|
Integer useCount = examineItem.getUseCount(); |
|
|
|
|
examineItem.setUseCount(++ useCount); |
|
|
|
|
examineItemService.updateById(examineItem); |
|
|
|
|
} |
|
|
|
|
if (type == 2) { |
|
|
|
|
ExamineWay examineWay = examineWayService.getById(elementId); |
|
|
|
|
Integer useCount = examineWay.getUseCount(); |
|
|
|
|
examineWay.setUseCount(++useCount); |
|
|
|
|
examineWayService.updateById(examineWay); |
|
|
|
|
} |
|
|
|
|
if (type == 3) { |
|
|
|
|
ExamineBasis examineBasis = examineBasisService.getById(elementId); |
|
|
|
|
Integer useCount = examineBasis.getUseCount(); |
|
|
|
|
examineBasis.setUseCount(++useCount); |
|
|
|
|
examineBasisService.updateById(examineBasis); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工具类: 补0 |
|
|
|
|
*/ |
|
|
|
|
private String fullByZero(int i) { |
|
|
|
|
return i < 10 ? "0" + i : String.valueOf(i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void entrustPrint(String id, HttpServletResponse response) { |
|
|
|
|
|
|
|
|
|
Entrust entrust = this.getById(id); |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>(); |
|
|
|
|
@ -1967,7 +1783,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 根据网络图片URL转成字节数组(弃用)
|
|
|
|
|
/** |
|
|
|
|
* 根据网络图片URL转成字节数组(弃用) |
|
|
|
|
*/ |
|
|
|
|
private static byte[] getFileStream(String url) { |
|
|
|
|
try { |
|
|
|
|
URL httpUrl = new URL(url); |
|
|
|
|
@ -1983,6 +1801,9 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 读输入流 |
|
|
|
|
*/ |
|
|
|
|
private static byte[] readInputStream(InputStream inStream) throws Exception { |
|
|
|
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); |
|
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
|
@ -1993,4 +1814,206 @@ public class EntrustServiceImpl extends BaseServiceImpl<EntrustMapper, Entrust> |
|
|
|
|
inStream.close(); |
|
|
|
|
return outStream.toByteArray(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 委托单入库/修改 |
|
|
|
|
*/ |
|
|
|
|
private void addOrUpdateEntrust(Entrust entrust, long id) { |
|
|
|
|
if (entrust.getId() != null) { |
|
|
|
|
this.updateById(entrust); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
entrust.setId(id); |
|
|
|
|
this.save(entrust); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否为合同新增委托单 |
|
|
|
|
*/ |
|
|
|
|
private Entrust isContractTypeEntrust(Entrust entrust) { |
|
|
|
|
if (entrust.getContractId() != null) { |
|
|
|
|
entrust.setEntrustType(2); |
|
|
|
|
Contract contract = new Contract(); |
|
|
|
|
contract.setId(entrust.getContractId()); |
|
|
|
|
contract.setStatus(2); |
|
|
|
|
contractService.updateById(contract); |
|
|
|
|
} else { |
|
|
|
|
entrust.setEntrustType(1); |
|
|
|
|
} |
|
|
|
|
return entrust; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 样品关联数据入库 |
|
|
|
|
*/ |
|
|
|
|
private Entrust addSimpleRel(Entrust entrust, long id) { |
|
|
|
|
List<SimpleRel> rels = new ArrayList<>(); |
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
|
|
|
|
|
String month1 = fullByZero(now.getMonthValue()); |
|
|
|
|
String day1 = fullByZero(now.getDayOfMonth()); |
|
|
|
|
String hour1 = fullByZero(now.getHour()); |
|
|
|
|
|
|
|
|
|
// 检测编号前缀
|
|
|
|
|
String[] strings = entrust.getAcceptanceNum().split("-"); |
|
|
|
|
String s = strings[1] + now.getYear() + month1 + day1 + hour1 + "-"; |
|
|
|
|
|
|
|
|
|
StringBuilder simpleName = new StringBuilder(); |
|
|
|
|
Integer simpleCount = 0; |
|
|
|
|
List<Map<String, Object>> list = entrust.getSimpleNames(); |
|
|
|
|
|
|
|
|
|
// 样品排序
|
|
|
|
|
for (int sort = 1; sort < list.size(); sort++) { |
|
|
|
|
Map<String, Object> map = list.get(sort); |
|
|
|
|
// 样品名称
|
|
|
|
|
String name = (String) map.get("simpleName"); |
|
|
|
|
simpleName.append(name).append(","); |
|
|
|
|
// 样品数量
|
|
|
|
|
Integer count = (Integer) map.get("simpleCount"); |
|
|
|
|
simpleCount += count; |
|
|
|
|
// 原始编号
|
|
|
|
|
String num = (String) map.get("originalNum"); |
|
|
|
|
String[] split = num.split("-"); |
|
|
|
|
int a = Integer.parseInt(split[0]); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
|
SimpleRel simpleRel = new SimpleRel(); |
|
|
|
|
if (entrust.getId() != null) { |
|
|
|
|
simpleRel.setEntrustId(entrust.getId()); |
|
|
|
|
} else { |
|
|
|
|
simpleRel.setEntrustId(id); |
|
|
|
|
} |
|
|
|
|
simpleRel.setSimpleName(name); |
|
|
|
|
simpleRel.setReagentNum(1); |
|
|
|
|
simpleRel.setReagentExperieNum(s + ((a - 1) * 2 + i + 1 + count)); |
|
|
|
|
simpleRel.setExamineNum(1); |
|
|
|
|
simpleRel.setExamineExperieNum(s + ((a - 1) * 2 + i + 1)); |
|
|
|
|
simpleRel.setRecessiveNum((i + a) + ""); |
|
|
|
|
simpleRel.setOriginalNum((i + a) + ""); |
|
|
|
|
simpleRel.setStatus(0); |
|
|
|
|
simpleRel.setSort(sort); |
|
|
|
|
rels.add(simpleRel); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
simpleRelService.saveBatch(rels); |
|
|
|
|
// 委托单内容补充
|
|
|
|
|
entrust.setSimpleName(simpleName.toString()); |
|
|
|
|
entrust.setSimpleCount(simpleCount); |
|
|
|
|
String originalNum = "01-" + fullByZero(simpleCount); |
|
|
|
|
|
|
|
|
|
entrust.setIsDeleted(0); |
|
|
|
|
entrust.setCreateUser(null); |
|
|
|
|
entrust.setUpdateUser(null); |
|
|
|
|
entrust.setEntrustStatus("1"); |
|
|
|
|
entrust.setCreateTime(new Date()); |
|
|
|
|
entrust.setUpdateTime(new Date()); |
|
|
|
|
entrust.setOriginalNum(originalNum); |
|
|
|
|
entrust.setSimpleJson(JSON.toJSONString(entrust.getSimpleNames())); |
|
|
|
|
if (entrust.getSampleReceiverId() != null) { |
|
|
|
|
R<User> userR = userClient.userInfoById(Long.valueOf(entrust.getSampleReceiverId())); |
|
|
|
|
User data = userR.getData(); |
|
|
|
|
if (data != null) { |
|
|
|
|
entrust.setSampleReceiverName(data.getName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return entrust; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 如果有就取用,没有就新增 |
|
|
|
|
* 有共同点,待抽 |
|
|
|
|
*/ |
|
|
|
|
private void addIfNull(Entrust entrust) { |
|
|
|
|
// 送检单位
|
|
|
|
|
EntrustCustomer byId = customerService.getById(entrust.getEntrustCustomerId()); |
|
|
|
|
if (byId != null) { |
|
|
|
|
entrust.setEntrustCustomerName(byId.getName()); |
|
|
|
|
} else { |
|
|
|
|
EntrustCustomer customer = new EntrustCustomer(); |
|
|
|
|
customer.setStatus(1); |
|
|
|
|
customer.setPhone(entrust.getPhone()); |
|
|
|
|
customer.setId(RandomUtils.nextLong()); |
|
|
|
|
customer.setFax(entrust.getFacsimile()); |
|
|
|
|
customer.setEmail(entrust.getPostalCode()); |
|
|
|
|
customer.setFullName(entrust.getSubmittedBy()); |
|
|
|
|
customer.setName(entrust.getEntrustCustomerName()); |
|
|
|
|
customerService.save(customer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 采样单位
|
|
|
|
|
EntrustCustomer byId1 = customerService.getById(entrust.getTakeCompanyId()); |
|
|
|
|
if (byId1 != null) { |
|
|
|
|
entrust.setTakeCompany(byId1.getName()); |
|
|
|
|
} else { |
|
|
|
|
EntrustCustomer customer = new EntrustCustomer(); |
|
|
|
|
customer.setStatus(2); |
|
|
|
|
customer.setId(RandomUtils.nextLong()); |
|
|
|
|
customer.setPhone(entrust.getTakePhone()); |
|
|
|
|
customer.setName(entrust.getTakeCompany()); |
|
|
|
|
customer.setFullName(entrust.getTakePerson()); |
|
|
|
|
customer.setAddress(entrust.getTakeCompanyAddress()); |
|
|
|
|
customerService.save(customer); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新增或修改检验集合 |
|
|
|
|
*/ |
|
|
|
|
private void addOrUpdateExamines(List<Examine> examines, Long entrustId) { |
|
|
|
|
if (CollectionUtils.isNotEmpty(examines)) { |
|
|
|
|
List<Examine> saveList = new ArrayList<>(); |
|
|
|
|
List<Examine> updateList = new ArrayList<>(); |
|
|
|
|
for (int i = 0; i < examines.size(); i++) { |
|
|
|
|
Examine examine = examines.get(i); |
|
|
|
|
if (examine.getId() != null) { |
|
|
|
|
updateList.add(examine); |
|
|
|
|
} else { |
|
|
|
|
examine.setStatus(0); |
|
|
|
|
examine.setIsDeleted(0); |
|
|
|
|
examine.setSimpleCount(0); |
|
|
|
|
examine.setExperieNum(""); |
|
|
|
|
examine.setExamineOrder(i + 1); |
|
|
|
|
examine.setEntrustId(entrustId); |
|
|
|
|
examine.setCreateTime(new Date()); |
|
|
|
|
examine.setUpdateTime(new Date()); |
|
|
|
|
saveList.add(examine); |
|
|
|
|
} |
|
|
|
|
// 使用次数 +1 操作
|
|
|
|
|
addUseCount(1, examine.getExamineItemId()); |
|
|
|
|
addUseCount(2, examine.getExamineWayId()); |
|
|
|
|
addUseCount(3, examine.getExamineBasisId()); |
|
|
|
|
} |
|
|
|
|
examineService.saveBatch(saveList); |
|
|
|
|
examineService.updateBatchById(updateList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addUseCount(int type, Long elementId) { |
|
|
|
|
if (elementId == null) { return; } |
|
|
|
|
if (type == 1) { |
|
|
|
|
ExamineItem examineItem = examineItemService.getById(elementId); |
|
|
|
|
Integer useCount = examineItem.getUseCount(); |
|
|
|
|
examineItem.setUseCount(++ useCount); |
|
|
|
|
examineItemService.updateById(examineItem); |
|
|
|
|
} |
|
|
|
|
if (type == 2) { |
|
|
|
|
ExamineWay examineWay = examineWayService.getById(elementId); |
|
|
|
|
Integer useCount = examineWay.getUseCount(); |
|
|
|
|
examineWay.setUseCount(++useCount); |
|
|
|
|
examineWayService.updateById(examineWay); |
|
|
|
|
} |
|
|
|
|
if (type == 3) { |
|
|
|
|
ExamineBasis examineBasis = examineBasisService.getById(elementId); |
|
|
|
|
Integer useCount = examineBasis.getUseCount(); |
|
|
|
|
examineBasis.setUseCount(++useCount); |
|
|
|
|
examineBasisService.updateById(examineBasis); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 工具类: 补0 |
|
|
|
|
*/ |
|
|
|
|
private String fullByZero(int i) { |
|
|
|
|
return i < 10 ? "0" + i : String.valueOf(i); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|