TCntrnoServiceImpl.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. package com.ruoyi.shipping.service.impl;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.math.BigDecimal;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.*;
  8. import java.util.concurrent.ConcurrentHashMap;
  9. import java.util.function.Function;
  10. import java.util.function.Predicate;
  11. import java.util.stream.Collectors;
  12. import com.alibaba.fastjson.JSONArray;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  15. import com.ruoyi.common.constant.UserConstants;
  16. import com.ruoyi.common.core.domain.AjaxResult;
  17. import com.ruoyi.common.core.domain.entity.SysDictData;
  18. import com.ruoyi.common.core.domain.model.LoginUser;
  19. import com.ruoyi.common.utils.DateUtils;
  20. import com.ruoyi.common.utils.SecurityUtils;
  21. import com.ruoyi.common.utils.StringUtils;
  22. import com.ruoyi.shipping.domain.*;
  23. import com.ruoyi.shipping.excel.*;
  24. import com.ruoyi.shipping.mapper.*;
  25. import com.ruoyi.system.mapper.SysDictDataMapper;
  26. import org.apache.poi.ss.usermodel.*;
  27. import org.apache.poi.ss.util.CellReference;
  28. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  29. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  30. import org.springframework.beans.BeanUtils;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.stereotype.Service;
  33. import com.ruoyi.shipping.service.ITCntrnoService;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import static com.ruoyi.common.utils.poi.Excel.filter;
  38. /**
  39. * 集装箱号Service业务层处理
  40. *
  41. * @author ruoyi
  42. * @date 2021-03-22
  43. */
  44. @Service
  45. public class TCntrnoServiceImpl implements ITCntrnoService {
  46. @Autowired
  47. private TCntrnoMapper tCntrnoMapper;
  48. @Autowired
  49. private TCntrtrackingMapper tCntrtrackingMapper;
  50. @Autowired
  51. private TCntrMapper tCntrMapper;
  52. @Autowired
  53. private SysDictDataMapper sysDictDataMapper;
  54. @Autowired
  55. private TAddressMapper tAddressMapper;
  56. @Autowired
  57. private TConditionAccessoryMapper tConditionAccessoryMapper;
  58. /**
  59. * 查询集装箱号
  60. *
  61. * @param fId 集装箱号ID
  62. * @return 集装箱号
  63. */
  64. @Override
  65. public TCntrno selectTCntrnoById(Long fId) {
  66. return tCntrnoMapper.selectTCntrnoById(fId);
  67. }
  68. /**
  69. * 查询集装箱号列表
  70. *
  71. * @param tCntrno 集装箱号
  72. * @return 集装箱号
  73. */
  74. @Override
  75. public List<TCntrno> selectTCntrnoList(TCntrno tCntrno) {
  76. return tCntrnoMapper.selectTCntrnoList(tCntrno);
  77. }
  78. /**
  79. * 新增集装箱号
  80. *
  81. * @param tCntrno 集装箱号
  82. * @return 结果
  83. */
  84. @Override
  85. public int insertTCntrno(TCntrno tCntrno) {
  86. tCntrno.setCreateTime(DateUtils.getNowDate());
  87. tCntrno.setCreateBy(SecurityUtils.getUsername());
  88. tCntrno.setfUpdatetime(DateUtils.getNowDate());
  89. tCntrno.setfStatus("T");
  90. return tCntrnoMapper.insertTCntrno(tCntrno);
  91. }
  92. /**
  93. * 修改集装箱号
  94. *
  95. * @param tCntrno 集装箱号
  96. * @return 结果
  97. */
  98. @Override
  99. @Transactional
  100. public int updateTCntrno(List<TCntrno> tCntrno) {
  101. int update = 0;
  102. if (CollectionUtils.isNotEmpty(tCntrno)) {
  103. for (TCntrno cntrno : tCntrno) {
  104. String remark = cntrno.getRemark();
  105. cntrno.setUpdateTime(DateUtils.getNowDate());
  106. cntrno.setUpdateBy(SecurityUtils.getUsername());
  107. //最新时间
  108. if (cntrno.getFoldtime() == null) {
  109. cntrno.setfUpdatetime(DateUtils.getNowDate());
  110. } else {
  111. cntrno.setfUpdatetime(cntrno.getFoldtime());
  112. }
  113. //调入地点
  114. if (StringUtils.isNotEmpty(cntrno.getFoldSite())) {
  115. cntrno.setfUpdateaddress(cntrno.getFoldSite());
  116. }
  117. //调入空重
  118. if (StringUtils.isNotEmpty(cntrno.getFoldFUpdateef())) {
  119. cntrno.setfUpdateef(cntrno.getFoldFUpdateef());
  120. }
  121. //调入状态
  122. if (StringUtils.isNotEmpty(cntrno.getFoldFCntrstatus())) {
  123. cntrno.setfCntrstatus(cntrno.getFoldFCntrstatus());
  124. }
  125. if (StringUtils.isNotEmpty(remark)) {
  126. cntrno.setRemark(null);
  127. }
  128. //更改t_cntro表信息
  129. update = tCntrnoMapper.updateTCntrno((cntrno));
  130. //保存信息
  131. TCntrno cntrnoById = tCntrnoMapper.selectTCntrnoById(cntrno.getfId());
  132. if (cntrnoById.getfStatus().equals("T") || cntrnoById.getfStatus().equals("正常")) {
  133. cntrnoById.setfStatus("T");
  134. } else {
  135. cntrnoById.setfStatus("F");
  136. }
  137. if (StringUtils.isNotEmpty(cntrno.getfMblno())) {//提单号
  138. cntrnoById.setfMblno(cntrno.getfMblno());
  139. }
  140. if (StringUtils.isNotEmpty(cntrno.getfVoy())) {//航次
  141. cntrnoById.setfVoy(cntrno.getfVoy());
  142. }
  143. if (StringUtils.isNotEmpty(cntrno.getfVsl())) {//船名
  144. cntrnoById.setfVsl(cntrno.getfVsl());
  145. }
  146. if (StringUtils.isNotEmpty(remark)) {
  147. cntrnoById.setRemark(remark);
  148. }
  149. TCntrtracking setfield = setfield(cntrnoById);
  150. tCntrtrackingMapper.insertTCntrtracking(setfield);
  151. if (CollectionUtils.isNotEmpty(cntrno.getAccessoryList())) {
  152. for (TConditionAccessory tConditionAccessory : cntrno.getAccessoryList()) {
  153. tConditionAccessory.setfOrgId(10L);
  154. tConditionAccessory.setfPid(setfield.getfId());
  155. tConditionAccessory.setCreateBy(SecurityUtils.getUsername());
  156. tConditionAccessory.setCreateTime(DateUtils.getNowDate());
  157. tConditionAccessoryMapper.insertTConditionAccessory(tConditionAccessory);
  158. }
  159. }
  160. }
  161. }
  162. return update;
  163. }
  164. @Override
  165. @Transactional
  166. public AjaxResult updateAirForceStation(List<TCntrno> tCntrno) {
  167. int update = 0;
  168. if (CollectionUtils.isNotEmpty(tCntrno)) {
  169. for (TCntrno cntrno : tCntrno) {
  170. String remark = cntrno.getRemark();
  171. cntrno.setUpdateTime(DateUtils.getNowDate());
  172. cntrno.setUpdateBy(SecurityUtils.getUsername());
  173. TCntrno cnTrNoByfNo = tCntrnoMapper.selectTCnTrNoByfNo(cntrno.getfNo());
  174. if (cnTrNoByfNo == null){
  175. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  176. return AjaxResult.error("箱号:"+cntrno.getfNo()+"系统中不存在请维护");
  177. }else {
  178. cntrno.setfId(cnTrNoByfNo.getfId());
  179. //更改t_cntro表信息
  180. update = tCntrnoMapper.updateTCntrno((cntrno));
  181. }
  182. //保存历史信息
  183. TCntrno cntrnoById = tCntrnoMapper.selectTCntrnoById(cntrno.getfId());
  184. if (cntrnoById.getfStatus().equals("T") || cntrnoById.getfStatus().equals("正常")) {
  185. cntrnoById.setfStatus("T");
  186. } else {
  187. cntrnoById.setfStatus("F");
  188. }
  189. if (StringUtils.isNotEmpty(cntrno.getfMblno())) {//提单号
  190. cntrnoById.setfMblno(cntrno.getfMblno());
  191. }
  192. if (StringUtils.isNotEmpty(cntrno.getfVoy())) {//航次
  193. cntrnoById.setfVoy(cntrno.getfVoy());
  194. }
  195. if (StringUtils.isNotEmpty(cntrno.getfVsl())) {//船名
  196. cntrnoById.setfVsl(cntrno.getfVsl());
  197. }
  198. if (StringUtils.isNotEmpty(remark)) {
  199. cntrnoById.setRemark(remark);
  200. }
  201. TCntrtracking setfield = setfield(cntrnoById);
  202. update = tCntrtrackingMapper.insertTCntrtracking(setfield);
  203. }
  204. }
  205. if (update <= 0 ){
  206. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  207. return AjaxResult.error("保存场站信息失败");
  208. }
  209. return AjaxResult.success();
  210. }
  211. @Override
  212. @Transactional
  213. public int updateTCntrnoMessage(TCntrno tCntrno) {
  214. tCntrno.setUpdateTime(DateUtils.getNowDate());
  215. tCntrno.setUpdateBy(SecurityUtils.getUsername());
  216. tCntrno.setfUpdatetime(DateUtils.getNowDate());
  217. if (tCntrno.getfStatus().equals("T") || tCntrno.getfStatus().equals("正常")) {
  218. tCntrno.setfStatus("T");
  219. } else {
  220. tCntrno.setfStatus("F");
  221. }
  222. TCntrtracking setfield = setfield(tCntrno);
  223. tCntrtrackingMapper.insertTCntrtracking(setfield);
  224. //更改t_cntro表信息
  225. return tCntrnoMapper.updateTCntrno((tCntrno));
  226. }
  227. /**
  228. * 批量删除集装箱号
  229. *
  230. * @param fIds 需要删除的集装箱号ID
  231. * @return 结果
  232. */
  233. @Override
  234. public int deleteTCntrnoByIds(Long[] fIds) {
  235. return tCntrnoMapper.deleteTCntrnoByIds(fIds);
  236. }
  237. /**
  238. * 删除集装箱号信息
  239. *
  240. * @param fId 集装箱号ID
  241. * @return 结果
  242. */
  243. @Override
  244. public int deleteTCntrnoById(Long fId) {
  245. return tCntrnoMapper.deleteTCntrnoById(fId);
  246. }
  247. /**
  248. * 批量更新数据状态将正常状态改为停用
  249. *
  250. * @param fIds
  251. * @return
  252. */
  253. @Override
  254. public int updateTcntrnoStatus(Long[] fIds) {
  255. return tCntrnoMapper.updateTcntrnoStatus(fIds);
  256. }
  257. @Override
  258. public List<TCntrno> selectTcntrnoMessage(TCntrno tCntrno) {
  259. return tCntrnoMapper.selectTcntrnoMessage(tCntrno, null, null, null, null, null);
  260. }
  261. @Override
  262. public List<Map<String, Object>> getTCntrnoMessage(TCntrno tCntrno) {
  263. StringBuffer stringBuffer = new StringBuffer();
  264. List<String> list = tCntrMapper.selectTCntrFNo();
  265. String sql = null;
  266. if (CollectionUtils.isNotEmpty(list)) {
  267. for (String s : list) {
  268. stringBuffer.append("MAX( CASE WHEN tt.f_no = '" + s);
  269. stringBuffer.append("' THEN tt.typeidCount ELSE 0 END ) AS '" + s + "',");
  270. }
  271. sql = stringBuffer.subSequence(0, stringBuffer.length() - 1).toString();
  272. }
  273. return tCntrnoMapper.getTCntrnoMessage(sql, tCntrno);
  274. }
  275. @Override
  276. public List<TCntrno> getTCntrnoDistribute(TCntrno tCntrno) {
  277. //箱类型不为空查箱类型id
  278. String address = null;//地点
  279. String typeidName = null;//箱类型
  280. String cntrstatusName = null;//箱状态
  281. String updateEFName = null;//空重
  282. if (StringUtils.isNotEmpty(tCntrno.getAddressName())) {
  283. address = tCntrno.getAddressName();
  284. }
  285. if (StringUtils.isNotEmpty(tCntrno.getTypeidName())) {
  286. typeidName = tCntrno.getTypeidName();
  287. }
  288. //箱状态不为空查箱状态
  289. if (StringUtils.isNotEmpty(tCntrno.getCntrstatusName())) {
  290. cntrstatusName = tCntrno.getCntrstatusName();
  291. }
  292. //箱空重部位空查空重
  293. if (StringUtils.isNotEmpty(tCntrno.getUpdateEFName())) {
  294. updateEFName = tCntrno.getUpdateEFName();
  295. }
  296. return tCntrnoMapper.selectTcntrnoMessage(tCntrno, address, typeidName, cntrstatusName, updateEFName, tCntrno.getCntrsize());
  297. }
  298. @Override
  299. public List<String> getTCntrnoChange(TCntrno tCntrno) {
  300. List<String> key = new ArrayList<>();
  301. key.add("地点");
  302. List<String> list = tCntrMapper.selectTCntrFNo();
  303. key.addAll(list);
  304. key.add("空");
  305. key.add("重");
  306. key.add("好");
  307. key.add("坏");
  308. return key;
  309. }
  310. @Override
  311. public String selectTCntrnoFNo(TCntrno tCntrno) {
  312. TCntrno cntrno = tCntrnoMapper.selectTCntrnoFNo(tCntrno);
  313. if (StringUtils.isNotNull(cntrno) && !cntrno.getfId().equals(tCntrno.getfId())) {
  314. return UserConstants.NOT_UNIQUE;
  315. }
  316. return UserConstants.UNIQUE;
  317. }
  318. /**
  319. * 后续维护
  320. *
  321. * @param fileName 更新箱信息数据列表
  322. * @return
  323. */
  324. @Override
  325. public AjaxResult importUpdateDataTcntrnoExcel(MultipartFile fileName) {
  326. return null;
  327. }
  328. /**
  329. * 后续维护
  330. *
  331. * @param fileName 更新箱信息数据列表
  332. * @return
  333. */
  334. @Override
  335. public AjaxResult importTcntrnoDataExcel(MultipartFile fileName) {
  336. return null;
  337. }
  338. @Override
  339. public AjaxResult importCreateCompanyMsg(MultipartFile file) throws Exception {
  340. List<TCntrnoExcel> fleetCompanyMsgs = new ArrayList<>();
  341. InputStream inputStream = null;
  342. try {
  343. inputStream = file.getInputStream();
  344. String originalFilename = file.getOriginalFilename();
  345. Workbook workbook = null;
  346. if (originalFilename.endsWith("xls")) {
  347. workbook = WorkbookFactory.create(inputStream);
  348. } else if (originalFilename.endsWith("xlsx")) {
  349. workbook = new XSSFWorkbook(inputStream);
  350. }
  351. Sheet sheet = workbook.getSheetAt(0);
  352. int line = 0;
  353. for (Row rows : sheet) {
  354. line++;
  355. if (rows.getRowNum() == 0) {
  356. continue;
  357. }
  358. TCntrnoExcel companyMsg = new TCntrnoExcel();
  359. for (int a = 0; a < rows.getPhysicalNumberOfCells(); a++) {
  360. Cell cell = rows.getCell(a);
  361. if (cell == null){
  362. continue;
  363. }
  364. String value = filter(sheet.getRow(0), CellReference.convertNumToColString(cell.getColumnIndex()));
  365. switch (value) {
  366. case "箱号":
  367. //设置单元格类型
  368. cell.setCellType(CellType.STRING);
  369. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  370. /*return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少箱号");*/
  371. break;
  372. }
  373. companyMsg.setfNo(cell.getStringCellValue());
  374. break;
  375. case "箱类型":
  376. //设置单元格类型
  377. cell.setCellType(CellType.STRING);
  378. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  379. /*return AjaxResult.error("Excel箱信息数据第" + line + "箱类型");*/
  380. break;
  381. }
  382. companyMsg.setTypeidName(cell.getStringCellValue());
  383. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  384. Long fId = tCntrMapper.selectRcntrFId(companyMsg.getTypeidName());
  385. companyMsg.setfTypeid(fId);
  386. }
  387. break;
  388. case "最新地点":
  389. //设置单元格类型
  390. cell.setCellType(CellType.STRING);
  391. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  392. /*return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少最新地点");*/
  393. break;
  394. }
  395. companyMsg.setAddressName((cell.getStringCellValue()));
  396. break;
  397. case "箱主":
  398. //设置单元格类型
  399. cell.setCellType(CellType.STRING);
  400. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  401. /*return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少货名");*/
  402. break;
  403. }
  404. companyMsg.setOwnerName(cell.getStringCellValue());
  405. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  406. String fPackageid = sysDictDataMapper.selectDictValue("f_owner", cell.getStringCellValue());
  407. if (StringUtils.isNotEmpty(fPackageid)) {
  408. companyMsg.setfOwner(fPackageid);
  409. }
  410. }
  411. break;
  412. case "箱状态":
  413. //设置单元格类型
  414. cell.setCellType(CellType.STRING);
  415. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  416. /*return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少箱状态");*/
  417. break;
  418. }
  419. companyMsg.setCntrstatusName(cell.getStringCellValue());
  420. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  421. String setCntrstatusid = sysDictDataMapper.selectDictValue("f_cntrstatus", cell.getStringCellValue());
  422. if (StringUtils.isNotEmpty(setCntrstatusid)) {
  423. companyMsg.setfCntrstatus(setCntrstatusid);
  424. }
  425. }
  426. break;
  427. case "空重":
  428. //设置单元格类型
  429. cell.setCellType(CellType.STRING);
  430. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  431. /*return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少箱型");*/
  432. break;
  433. }
  434. companyMsg.setUpdateEFName(cell.getStringCellValue());
  435. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  436. String setUpdateEFid = sysDictDataMapper.selectDictValue("f_updateEF", cell.getStringCellValue());
  437. if (StringUtils.isNotEmpty(setUpdateEFid)) {
  438. companyMsg.setfUpdateef(setUpdateEFid);
  439. }
  440. }
  441. break;
  442. case "地点类型":
  443. //设置单元格类型
  444. cell.setCellType(CellType.STRING);
  445. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  446. /*return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少地点类型");*/
  447. break;
  448. }
  449. companyMsg.setAddressType(cell.getStringCellValue());
  450. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  451. String fPackageid = sysDictDataMapper.selectDictValue("f_types", cell.getStringCellValue());
  452. if (StringUtils.isNotEmpty(fPackageid)) {
  453. companyMsg.setAddressTypeId(fPackageid);
  454. }
  455. }
  456. break;
  457. /*case "箱来源":
  458. //设置单元格类型
  459. cell.setCellType(CellType.STRING);
  460. companyMsg.setSourceName(cell.getStringCellValue());
  461. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  462. String setSourceid = sysDictDataMapper.selectDictValue("f_source", cell.getStringCellValue());
  463. if (StringUtils.isNotEmpty(setSourceid)) {
  464. companyMsg.setfSource(setSourceid);
  465. }
  466. }
  467. break;
  468. case "租赁方式":
  469. //设置单元格类型
  470. cell.setCellType(CellType.STRING);
  471. companyMsg.setRentName(cell.getStringCellValue());
  472. if (StringUtils.isNotEmpty(cell.getStringCellValue())) {
  473. String setRentid = sysDictDataMapper.selectDictValue("f_rent", cell.getStringCellValue());
  474. if (StringUtils.isNotEmpty(setRentid)) {
  475. companyMsg.setfRent(setRentid);
  476. }
  477. }
  478. break;
  479. case "备注":
  480. //设置单元格类型
  481. cell.setCellType(CellType.STRING);
  482. companyMsg.setRemark(cell.getStringCellValue());
  483. break;*/
  484. }
  485. if (StringUtils.isNotEmpty(companyMsg.getAddressName()) && StringUtils.isNotEmpty(companyMsg.getAddressTypeId())) {
  486. TAddress tAddress = new TAddress();
  487. tAddress.setfName(companyMsg.getAddressName());
  488. tAddress.setfTypes(companyMsg.getAddressTypeId());
  489. TAddress address = tAddressMapper.selectAddressFName(tAddress);
  490. if (address != null){
  491. companyMsg.setfUpdateaddress(address.getfId().toString());
  492. }
  493. }
  494. }
  495. fleetCompanyMsgs.add(companyMsg);
  496. }
  497. fleetCompanyMsgs = fleetCompanyMsgs.stream().filter(distinctByKey(TCntrnoExcel::getfNo)).collect(Collectors.toList());
  498. } catch (IOException e) {
  499. return AjaxResult.error("上传文件失败,请检查文件是否损坏");
  500. }
  501. return AjaxResult.success("success", fleetCompanyMsgs);
  502. }
  503. @Override
  504. @Transactional
  505. public AjaxResult batch(String tCntrno, LoginUser loginUser) {
  506. JSONArray jsonCrArray = JSONArray.parseArray(tCntrno);
  507. List<TCntrno> tCntrnoList = JSONObject.parseArray(jsonCrArray.toJSONString(), TCntrno.class);
  508. StringBuffer stringBuffer = new StringBuffer();
  509. if (CollectionUtils.isNotEmpty(tCntrnoList)) {
  510. for (TCntrno cntrno : tCntrnoList) {
  511. if (UserConstants.NOT_UNIQUE.equals(this.selectTCntrnoFNo(cntrno))) {
  512. stringBuffer.append(cntrno.getfNo() + "编号已存在,");
  513. continue;
  514. } else {
  515. cntrno.setCreateTime(DateUtils.getNowDate());
  516. cntrno.setCreateBy(SecurityUtils.getUsername());
  517. cntrno.setfUpdatetime(DateUtils.getNowDate());
  518. cntrno.setfStatus("T");
  519. tCntrnoMapper.insertTCntrno(cntrno);
  520. }
  521. }
  522. }
  523. if (StringUtils.isNotEmpty(stringBuffer)){
  524. return AjaxResult.success("success",stringBuffer.toString());
  525. }else {
  526. return AjaxResult.success();
  527. }
  528. }
  529. @Override
  530. public List<Map<String, Object>> getTcntrnoFno(TCntrno tCntrno) {
  531. return tCntrnoMapper.getTcntrnoFno(tCntrno);
  532. }
  533. @Override
  534. public AjaxResult importAirForceStation(MultipartFile file) throws Exception{
  535. List<TCntrno> tCntrno = new ArrayList<>();
  536. InputStream inputStream = null;
  537. inputStream = file.getInputStream();
  538. String originalFilename = file.getOriginalFilename();
  539. Workbook workbook = null;
  540. if (originalFilename.endsWith("xls")){
  541. workbook = WorkbookFactory.create(inputStream);
  542. }else if (originalFilename.endsWith("xlsx")){
  543. workbook = new XSSFWorkbook(inputStream);
  544. }
  545. Sheet sheet = workbook.getSheetAt(0);
  546. int line = 0;
  547. for (Row rows : sheet) {
  548. line++;
  549. if (rows.getRowNum() == 0) {
  550. continue;
  551. }
  552. TCntrno companyMsg = new TCntrno();
  553. for (int a = 0; a < rows.getPhysicalNumberOfCells(); a++) {
  554. Cell cell = rows.getCell(a);
  555. String value = filter(sheet.getRow(0), CellReference.convertNumToColString(cell.getColumnIndex()));
  556. switch (value) {
  557. case "箱动态":
  558. //设置单元格类型
  559. cell.setCellType(CellType.STRING);
  560. companyMsg.setOpctnstatusName(cell.getStringCellValue());
  561. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  562. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少箱动态");
  563. }
  564. String fOpCTnsTaTus = sysDictDataMapper.selectDictValue("f_opctnstatus", cell.getStringCellValue());
  565. if (StringUtils.isEmpty(fOpCTnsTaTus)){
  566. return AjaxResult.error("系统缺少箱动态"+cell.getStringCellValue()+"请维护");
  567. }
  568. companyMsg.setfOpctnstatus(fOpCTnsTaTus);
  569. break;
  570. case "箱号":
  571. //设置单元格类型
  572. cell.setCellType(CellType.STRING);
  573. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  574. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少箱号");
  575. }
  576. companyMsg.setfNo(cell.getStringCellValue());
  577. break;
  578. case "空重":
  579. //设置单元格类型
  580. cell.setCellType(CellType.STRING);
  581. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  582. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少空重");
  583. }
  584. String fUpDaTeEf = sysDictDataMapper.selectDictValue("f_updateEF", cell.getStringCellValue());
  585. if (StringUtils.isEmpty(fUpDaTeEf)){
  586. return AjaxResult.error("系统缺少空重:"+cell.getStringCellValue()+"请维护");
  587. }
  588. companyMsg.setfUpdateef(fUpDaTeEf);
  589. break;
  590. case "动态日期":
  591. //设置单元格类型
  592. cell.setCellType(CellType.STRING);
  593. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  594. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少动态日期");
  595. }
  596. Date tDate = new Date();
  597. long localOffset = tDate.getTimezoneOffset() * 60000; //系统时区偏移 1900/1/1 到 1970/1/1 的 25569 天
  598. tDate.setTime((long) ((Double.valueOf(cell.getStringCellValue()) - 25569) * 24 * 3600 * 1000 + localOffset));
  599. companyMsg.setUpdateTime(tDate);
  600. break;
  601. case "船名":
  602. //设置单元格类型
  603. cell.setCellType(CellType.STRING);
  604. /*if (StringUtils.isEmpty(cell.getStringCellValue())) {
  605. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少船名");
  606. }*/
  607. companyMsg.setfVsl(cell.getStringCellValue());
  608. break;
  609. case "航次":
  610. //设置单元格类型
  611. cell.setCellType(CellType.STRING);
  612. /*if (StringUtils.isEmpty(cell.getStringCellValue())) {
  613. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少航次");
  614. }*/
  615. companyMsg.setfVoy(cell.getStringCellValue());
  616. break;
  617. case "重量":
  618. //设置单元格类型
  619. cell.setCellType(CellType.STRING);
  620. /*if (StringUtils.isEmpty(cell.getStringCellValue())) {
  621. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少重量");
  622. }*/
  623. BigDecimal bigDecimal = new BigDecimal(cell.getStringCellValue());
  624. companyMsg.setfBoxWeight(bigDecimal);
  625. break;
  626. case "港口名称":
  627. //设置单元格类型
  628. cell.setCellType(CellType.STRING);
  629. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  630. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少港口名称");
  631. }
  632. String fTypes = sysDictDataMapper.selectDictValue("f_types", cell.getStringCellValue());
  633. if (StringUtils.isEmpty(fTypes)){
  634. return AjaxResult.error("系统缺少地点类型"+cell.getStringCellValue()+"请维护");
  635. }
  636. companyMsg.setPort(fTypes);
  637. companyMsg.setPortName(cell.getStringCellValue());
  638. break;
  639. case "堆放地点":
  640. //设置单元格类型
  641. cell.setCellType(CellType.STRING);
  642. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  643. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少堆放地点");
  644. }
  645. companyMsg.setAddressName(cell.getStringCellValue());
  646. TAddress address = new TAddress();
  647. address.setfName(cell.getStringCellValue());
  648. if (StringUtils.isEmpty(companyMsg.getPort())){
  649. return AjaxResult.error("缺少地点类型"+companyMsg.getPortName());
  650. }
  651. address.setfTypes(companyMsg.getPort());
  652. List<TAddress> tAddresses = tAddressMapper.selectTAddressBasicList(address);
  653. if (CollectionUtils.isEmpty(tAddresses)){
  654. return AjaxResult.error("系统缺少类型为"+companyMsg.getPortName()+"的地点"+cell.getStringCellValue()+"请维护");
  655. }
  656. companyMsg.setfUpdateaddress(tAddresses.get(0).getfId().toString());
  657. break;
  658. case "提单号":
  659. //设置单元格类型
  660. cell.setCellType(CellType.STRING);
  661. /*if (StringUtils.isEmpty(cell.getStringCellValue())) {
  662. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少提单号");
  663. }*/
  664. companyMsg.setfMblno(cell.getStringCellValue());
  665. break;
  666. case "铅封号":
  667. //设置单元格类型
  668. cell.setCellType(CellType.STRING);
  669. /*if (StringUtils.isEmpty(cell.getStringCellValue())) {
  670. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少铅封号");
  671. }*/
  672. companyMsg.setfSealno(cell.getStringCellValue());
  673. break;
  674. case "是否箱损":
  675. //设置单元格类型
  676. cell.setCellType(CellType.STRING);
  677. companyMsg.setCntrstatusName(cell.getStringCellValue());
  678. if (StringUtils.isEmpty(cell.getStringCellValue())) {
  679. return AjaxResult.error("Excel箱信息数据第" + line + "行数据缺少箱损状态");
  680. }
  681. String fCnTrsTaTus = sysDictDataMapper.selectDictValue("f_cntrstatus", cell.getStringCellValue());
  682. if (StringUtils.isEmpty(fCnTrsTaTus)){
  683. return AjaxResult.error("系统缺少箱状态"+cell.getStringCellValue()+"请维护");
  684. }
  685. companyMsg.setfCntrstatus(fCnTrsTaTus);
  686. break;
  687. case "箱损描述(备注)":
  688. //设置单元格类型
  689. cell.setCellType(CellType.STRING);
  690. companyMsg.setRemark(cell.getStringCellValue());
  691. break;
  692. }
  693. }
  694. tCntrno.add(companyMsg);
  695. }
  696. return AjaxResult.success("success", tCntrno);
  697. }
  698. @Override
  699. public List<BoxDistributionStatistics> boxDistributedStatistics() {
  700. List<BoxDistributionStatistics> list = new ArrayList<>();
  701. //先获取箱地址为港口信息
  702. List<TCntrno> boxPortMessage = tCntrnoMapper.getBoxPortMessage();
  703. //获取箱信息地址不为港口的信息
  704. List<TCntrno> addressMessageList = tCntrnoMapper.getBoxAddressMessage();
  705. //获取箱动态信息
  706. List<SysDictData> fOpcTnsTaTus = sysDictDataMapper.selectDictDataByType("f_opctnstatus");
  707. //在获取港口下的堆场对应的箱信息
  708. if (CollectionUtils.isNotEmpty(boxPortMessage) && CollectionUtils.isNotEmpty(fOpcTnsTaTus)){
  709. for (TCntrno cntrno : boxPortMessage) {
  710. BoxDistributionStatistics boxDistributionStatistics = new BoxDistributionStatistics();
  711. boxDistributionStatistics.setHaven(cntrno.getAddressName());
  712. List<BoxAddressMessage> boxAddressMessageList = new ArrayList<>();
  713. if (CollectionUtils.isNotEmpty(addressMessageList)){
  714. for (TCntrno trno : addressMessageList) {
  715. if (cntrno.getAddressName().equals(trno.getPortName()) && !trno.getAddressName().equals("在船")){
  716. BoxAddressMessage boxAddressMessage = new BoxAddressMessage();
  717. boxAddressMessage.setAddress(trno.getAddressName());
  718. boxAddressMessage.setNumberSize(fOpcTnsTaTus.size());
  719. List<BoxMessage> boxMessageList = new ArrayList<>();
  720. for (SysDictData opcTnsTaTus : fOpcTnsTaTus) {
  721. TCntrno tro = new TCntrno();
  722. BoxMessage boxMessage = new BoxMessage();
  723. tro.setfUpdateaddress(trno.getfUpdateaddress());
  724. tro.setfOpctnstatus(opcTnsTaTus.getDictValue());
  725. BoxMessage message = tCntrnoMapper.boxDistributionStatistics(tro);
  726. if (message != null){
  727. boxMessage = message;
  728. }
  729. boxMessage.setOpcTnStatus(opcTnsTaTus.getDictLabel());
  730. boxMessage.setUNIT(boxMessage.getTWENTYFR() +boxMessage.getTWENTYGP() + boxMessage.getTWENTYOT()
  731. +boxMessage.getTWENTYRF()+boxMessage.getTWENTYTK() +boxMessage.getFORTYFR()+boxMessage.getFORTYGP()
  732. +boxMessage.getFORTYHC()+boxMessage.getFORTYHR()+boxMessage.getFORTYOT()+boxMessage.getFORTYTK());
  733. boxMessage.setTEU(boxMessage.getTWENTYFR() +boxMessage.getTWENTYGP() + boxMessage.getTWENTYOT()
  734. +boxMessage.getTWENTYRF()+boxMessage.getTWENTYTK() +boxMessage.getFORTYFR()*2+boxMessage.getFORTYGP()*2
  735. +boxMessage.getFORTYHC()*2+boxMessage.getFORTYHR()*2+boxMessage.getFORTYOT()*2+boxMessage.getFORTYTK()*2);
  736. boxMessageList.add(boxMessage);
  737. }
  738. boxAddressMessage.setBoxMessages(boxMessageList);
  739. boxAddressMessageList.add(boxAddressMessage);
  740. }else if (cntrno.getAddressName().equals(trno.getPortName()) && trno.getAddressName().equals("在船")){
  741. //获取在船的备注
  742. List<TCntrno> boxRemark = tCntrnoMapper.getBoxRemark(trno.getfUpdateaddress());
  743. if (CollectionUtils.isNotEmpty(boxRemark)){
  744. for (TCntrno tCntrno : boxRemark) {
  745. BoxAddressMessage boxAddressMessage = new BoxAddressMessage();
  746. boxAddressMessage.setAddress(trno.getAddressName()+tCntrno.getRemark());
  747. boxAddressMessage.setNumberSize(fOpcTnsTaTus.size());
  748. List<BoxMessage> boxMessageList = new ArrayList<>();
  749. for (SysDictData opcTnsTaTus : fOpcTnsTaTus) {
  750. TCntrno tro = new TCntrno();
  751. BoxMessage boxMessage = new BoxMessage();
  752. tro.setfUpdateaddress(trno.getfUpdateaddress());
  753. tro.setfOpctnstatus(opcTnsTaTus.getDictValue());
  754. tro.setRemark(tCntrno.getRemark());
  755. BoxMessage message = tCntrnoMapper.boxDistributionStatistics(tro);
  756. if (message != null){
  757. boxMessage = message;
  758. }
  759. boxMessage.setOpcTnStatus(opcTnsTaTus.getDictLabel());
  760. boxMessage.setUNIT(boxMessage.getTWENTYFR() +boxMessage.getTWENTYGP() + boxMessage.getTWENTYOT()
  761. +boxMessage.getTWENTYRF()+boxMessage.getTWENTYTK() +boxMessage.getFORTYFR()+boxMessage.getFORTYGP()
  762. +boxMessage.getFORTYHC()+boxMessage.getFORTYHR()+boxMessage.getFORTYOT()+boxMessage.getFORTYTK());
  763. boxMessage.setTEU(boxMessage.getTWENTYFR() +boxMessage.getTWENTYGP() + boxMessage.getTWENTYOT()
  764. +boxMessage.getTWENTYRF()+boxMessage.getTWENTYTK() +boxMessage.getFORTYFR()*2+boxMessage.getFORTYGP()*2
  765. +boxMessage.getFORTYHC()*2+boxMessage.getFORTYHR()*2+boxMessage.getFORTYOT()*2+boxMessage.getFORTYTK()*2);
  766. boxMessageList.add(boxMessage);
  767. }
  768. boxAddressMessage.setBoxMessages(boxMessageList);
  769. boxAddressMessageList.add(boxAddressMessage);
  770. }
  771. }
  772. }
  773. }
  774. }
  775. boxDistributionStatistics.setBoxAddressMessages(boxAddressMessageList);
  776. boxDistributionStatistics.setNumber(fOpcTnsTaTus.size()*boxAddressMessageList.size());
  777. list.add(boxDistributionStatistics);
  778. }
  779. }
  780. return list;
  781. }
  782. @Override
  783. public List<Map<String, Object>> homeBox() {
  784. return tCntrnoMapper.homeBox();
  785. }
  786. /**
  787. * set字段
  788. *
  789. * @param tCntrno
  790. * @return
  791. */
  792. public TCntrtracking setfield(TCntrno tCntrno) {
  793. TCntrtracking tCntrtracking = new TCntrtracking();
  794. BeanUtils.copyProperties(tCntrno, tCntrtracking);
  795. tCntrtracking.setfId(null);
  796. return tCntrtracking;
  797. }
  798. public List<String> GetMapKey(List<Map<String, Object>> listResult) {
  799. if ((listResult != null) && (!listResult.isEmpty())) {
  800. List listKey = new ArrayList();
  801. Map mapResult = (Map) listResult.get(0);
  802. Set mapKeySet = mapResult.keySet();
  803. String listHead = "";
  804. Iterator iteratorKey = mapKeySet.iterator();
  805. while (iteratorKey.hasNext()) {
  806. listHead = iteratorKey.next().toString();
  807. listKey.add(listHead);
  808. }
  809. return listKey;
  810. }
  811. return null;
  812. }
  813. private static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
  814. Map<Object, Boolean> seen = new ConcurrentHashMap<>();
  815. return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
  816. }
  817. }