EmsProdplanYearController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package com.steerinfo.ems.emsprodplanyear.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.ems.Utils.ExcelToolUtils;
  4. import com.steerinfo.ems.emsprodplanmonth.mapper.EmsProdplanMonthMapper;
  5. import com.steerinfo.ems.emsprodplanmonth.model.EmsProdplanMonth;
  6. import com.steerinfo.ems.emsprodplanmonth.service.IEmsProdplanMonthService;
  7. import com.steerinfo.ems.emsprodplanyear.mapper.EmsProdplanYearMapper;
  8. import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
  9. import com.steerinfo.ems.emsprodplanyear.service.IEmsProdplanYearService;
  10. import com.steerinfo.framework.controller.BaseRESTfulController;
  11. import com.steerinfo.framework.controller.RESTfulResult;
  12. import com.steerinfo.framework.service.pagehelper.PageList;
  13. import io.swagger.annotations.ApiImplicitParam;
  14. import io.swagger.annotations.ApiImplicitParams;
  15. import io.swagger.annotations.ApiOperation;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.io.File;
  20. import java.math.BigDecimal;
  21. import java.text.ParseException;
  22. import java.text.SimpleDateFormat;
  23. import java.util.*;
  24. import java.util.stream.Collectors;
  25. /**
  26. * EmsProdplanYear RESTful接口:
  27. * @author generator
  28. * @version 1.0-SNAPSHORT 2021-06-26 08:40
  29. * 类描述
  30. * 修订历史:
  31. * 日期:2021-06-26
  32. * 作者:generator
  33. * 参考:
  34. * 描述:EmsProdplanYear RESTful接口
  35. * @see null
  36. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  37. */
  38. @RestController
  39. @RequestMapping("/${api.version}/emsprodplanyears")
  40. public class EmsProdplanYearController extends BaseRESTfulController {
  41. @Autowired
  42. IEmsProdplanYearService emsProdplanYearService;
  43. @Autowired
  44. private EmsProdplanYearMapper emsProdplanYearMapper;
  45. @Autowired
  46. private EmsProdplanMonthMapper emsProdplanMonthMapper;
  47. @Autowired
  48. private IEmsProdplanMonthService emsProdplanMonthService;
  49. @ApiOperation(value="获取列表", notes="分页查询")
  50. @ApiImplicitParams({
  51. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  52. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  53. })
  54. @GetMapping(value = "/")
  55. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  56. PageList<EmsProdplanYear> list = emsProdplanYearService.queryForPage(parmas, pageNum, pageSize);
  57. return success(list);
  58. }
  59. /**
  60. * 根据前端传参,获取页面数据
  61. * @RequiresPermissions("emsprodplanyear:view")
  62. * @param parmas 参数列表
  63. * @param pageNum 开始页码
  64. * @param pageSize 一页多少
  65. * @return 返回一个带有分页信息的集合
  66. */
  67. @GetMapping(value = "/getList")
  68. public RESTfulResult getlist(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  69. // 因为页面产品/工序数量不同,所以获取;
  70. Integer parentNum = parmas.get("parentNum") == null ? 4: Integer.valueOf(parmas.get("parentNum").toString().trim());
  71. pageSize = pageSize * parentNum;
  72. PageList<EmsProdplanYear> list = emsProdplanYearService.queryForPage(parmas, pageNum, pageSize);
  73. // 根据月份汇总数据
  74. Map<String,List<EmsProdplanYear>> stringListMap =
  75. (HashMap<String, List<EmsProdplanYear>>) list.getList().stream().collect(
  76. Collectors.groupingBy(EmsProdplanYear::getYearmonth)
  77. );
  78. // HashMap无序,所以这里要转LinkedHashMap,并返回有序列表
  79. Map<String,List<EmsProdplanYear>> sortListMap = new LinkedHashMap<>();
  80. stringListMap.entrySet().stream().sorted(
  81. Map.Entry.comparingByKey()).forEachOrdered(x-> sortListMap.put(x.getKey(),x.getValue())
  82. );
  83. // 返回实际行数
  84. list.setTotal((long) Math.ceil(list.getTotal()/(double)parentNum));
  85. List mapList = new ArrayList<>();
  86. //数据,进行组装
  87. mapList.add(sortListMap);
  88. list.setList(mapList);
  89. return success(list);
  90. }
  91. @ApiOperation(value="获取列表", notes="分页模糊查询")
  92. @ApiImplicitParams({
  93. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  94. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  95. })
  96. @GetMapping(value = "/like/")
  97. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  98. PageList<EmsProdplanYear> list = emsProdplanYearService.queryLikeForPage(parmas, pageNum, pageSize);
  99. return success(list);
  100. }
  101. @ApiOperation(value="创建", notes="根据EmsProdplanYear对象创建")
  102. @ApiImplicitParam(name = "emsProdplanYear", value = "详细实体emsProdplanYear", required = true, dataType = "EmsProdplanYear")
  103. @PostMapping(value = "/", produces = "application/json;charset=UTF-8")
  104. public RESTfulResult add(@RequestBody EmsProdplanYear[] models) throws ParseException {
  105. String userId = JwtUtil.getUseridByToken();
  106. Calendar c = Calendar.getInstance();
  107. for (int i = 0; i < models.length; i++) {
  108. EmsProdplanYear model = models[i];
  109. Boolean lineBool = (model.getLine() == null || model.getLine().equals(""))
  110. && (model.getProductid() == null || model.getProductid().equals(""));
  111. if(lineBool){
  112. return failed(null,"工序为空");
  113. }
  114. if(model.getYearmonth() == null){
  115. return failed(null,"请选择时间");
  116. }
  117. if (model.getUnit() == null || model.getUnit().equals("")) {
  118. model.setUnit("吨");
  119. }
  120. Map map = new HashMap(16);
  121. map.put("line",model.getLine());
  122. map.put("yearmonth",new SimpleDateFormat("yyyy-MM").format(model.getYearmonth()));
  123. map.put("productid",model.getProductid());
  124. List list = emsProdplanYearService.getDateForProduct((HashMap<String, Object>) map);
  125. if (list.size()>0){
  126. return failed(null,"该月时间段数据已生成,无法再次生成");
  127. }
  128. model.setCjr(userId);
  129. model.setCjsj(new Date());
  130. emsProdplanYearService.add(model);
  131. int dayMax = emsProdplanYearService.getDaysOfMonth(model.getYearmonth());
  132. Integer sumWeight = 0;
  133. EmsProdplanMonth maxSqno = emsProdplanMonthService.getMaxSqno();
  134. String unit = "008";
  135. String productid = "";
  136. String workProcid = "";
  137. Double days = Double.valueOf(dayMax);
  138. switch (model.getParentid()) {
  139. case "LG":
  140. sumWeight = model.getWeight().intValue();
  141. productid="方坯";
  142. if (model.getLine().equals("AT2007")){
  143. productid="异型坯";
  144. }
  145. unit="008";
  146. workProcid = "AT2004";
  147. break;
  148. case "LT":
  149. sumWeight = model.getWeight().intValue();
  150. productid="生铁";
  151. unit="008";
  152. days -= 0.5;
  153. break;
  154. case "SJ":
  155. sumWeight = model.getWeight().intValue();
  156. productid="烧结矿";
  157. unit="008";
  158. break;
  159. case "ZG" :
  160. sumWeight = model.getWeight().intValue();
  161. productid="线材";
  162. if(model.getLine().equals("AT2007")) {
  163. productid="H型钢";
  164. }
  165. unit="008";
  166. break;
  167. case "FDC" :
  168. sumWeight = model.getWeight().intValue();
  169. productid="发电量";
  170. unit="006";
  171. // 发电厂合计
  172. //workProcid = "AT1006";
  173. break;
  174. case "JCS" :
  175. sumWeight = model.getWeight().intValue();
  176. productid="白灰粉";
  177. unit="008";
  178. break;
  179. case "JCW" :
  180. sumWeight = model.getWeight().intValue();
  181. productid="矿渣粉";
  182. unit="008";
  183. workProcid = model.getProductid();
  184. break;
  185. case "JJZ" :
  186. sumWeight = model.getWeight1().intValue() + model.getWeight2().intValue();
  187. productid="焦炭";
  188. unit="008";
  189. workProcid = "AT1007";
  190. break;
  191. case "JJF" :
  192. sumWeight = model.getWeight().intValue();
  193. if(model.getLine().equals("AT3009")) {
  194. productid = "粗苯";
  195. workProcid = "AT3009";
  196. }
  197. if (model.getLine().equals("AT3024")){
  198. productid="焦油";
  199. workProcid = "AT3024";//model.setLine("AT2011");
  200. }
  201. if(model.getLine().equals("AT3010")){
  202. productid="硫铵";
  203. workProcid = "AT3010";
  204. }
  205. if(model.getLine().equals("AT3025")){
  206. productid="硫酸";
  207. workProcid = "AT3025";
  208. }
  209. if(model.getLine().equals("AT2012")){
  210. productid="精煤";
  211. workProcid = "AT2012";
  212. }
  213. unit="008";
  214. //workProcid = "AT1007";
  215. break;
  216. case "JJH" :
  217. sumWeight = model.getWeight().intValue();
  218. productid="精煤";
  219. workProcid = "AT2012";
  220. unit="008";
  221. break;
  222. default: break;
  223. }
  224. int[] avgWeight = emsProdplanYearService.avgWeight(sumWeight,dayMax, days);
  225. for (int k = 0;k < dayMax;k++) {
  226. EmsProdplanMonth monModel = new EmsProdplanMonth();
  227. c.setTime(model.getYearmonth());
  228. c.add(Calendar.DATE, k);
  229. monModel.setMay(c.getTime());
  230. monModel.setUnit(unit);
  231. monModel.setProductid(productid);
  232. monModel.setWeightMonth(model.getWeight());
  233. if (workProcid.equals("")) {
  234. monModel.setWorkprocid(model.getLine());
  235. } else {
  236. monModel.setWorkprocid(workProcid);
  237. monModel.setWeightMonth(BigDecimal.valueOf(sumWeight));
  238. }
  239. monModel.setWeightOrigin(BigDecimal.valueOf(avgWeight[k]));
  240. monModel.setWeightDay(BigDecimal.valueOf(avgWeight[k]));
  241. monModel.setKxf_weight(BigDecimal.valueOf(avgWeight[k]));
  242. monModel.setYxf_weight(BigDecimal.valueOf(0));
  243. monModel.setJxdays("0");
  244. monModel.setMemo("根据年计划,系统自动生成。");
  245. monModel.setCreateman("系统");
  246. monModel.setCreatetime(new Date());
  247. monModel.setSqno(maxSqno.getSqno()+k);
  248. Map monMap = new HashMap();
  249. monMap.put("may",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
  250. monMap.put("workprocid","'"+monModel.getWorkprocid()+"'");
  251. monMap.put("productid",monModel.getProductid());
  252. monMap.put("startTime",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
  253. monMap.put("endTime",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
  254. List<EmsProdplanMonth> monList = emsProdplanMonthMapper.selectByParameters(monMap);
  255. if(monList.size()<=0){
  256. EmsProdplanMonth emsProdplanMonth = emsProdplanMonthService.add(monModel);
  257. } else {
  258. if((model.getParentid().equals("LG") && monModel.getProductid().equals("方坯")) || model.getParentid().equals("JJZ")) {
  259. //|| model.getParentid().equals("FDC")
  260. monModel.setKxf_weight(monList.get(0).getKxf_weight().add(monModel.getKxf_weight()));
  261. monModel.setWeightMonth(monList.get(0).getWeightMonth().add(monModel.getWeightMonth()));
  262. monModel.setWeightDay(monList.get(0).getWeightDay().add(monModel.getWeightDay()));
  263. monModel.setWeightOrigin(monList.get(0).getWeightOrigin().add(monModel.getWeightOrigin()));
  264. monModel.setId(monList.get(0).getId());
  265. emsProdplanMonthService.modify(monModel);
  266. }
  267. }
  268. }
  269. }
  270. return success();
  271. }
  272. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  273. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  274. @GetMapping(value = "/{id}")
  275. public RESTfulResult get(@PathVariable String id){
  276. EmsProdplanYear emsProdplanYear = emsProdplanYearService.getById(id);
  277. return success(emsProdplanYear);
  278. }
  279. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsProdplanYear信息来更新详细信息")
  280. @ApiImplicitParams({
  281. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  282. @ApiImplicitParam(name = "emsProdplanYear", value = "详细实体emsProdplanYear", required = true, dataType = "EmsProdplanYear")
  283. })
  284. @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
  285. public RESTfulResult update(@PathVariable String id, @RequestBody EmsProdplanYear model){
  286. model.setId(id);
  287. EmsProdplanYear emsProdplanYear = emsProdplanYearService.modify(model);
  288. return success(emsProdplanYear);
  289. }
  290. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  291. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  292. @DeleteMapping(value = "/delete", produces = "application/json;charset=UTF-8")
  293. public RESTfulResult delete(@RequestBody EmsProdplanYear[] models){
  294. if(models.length >= 1) {
  295. for (int i = 0; i < models.length; i++) {
  296. EmsProdplanYear m = models[i];
  297. if(m==null || m.getNo() ==null || m.getNo().isEmpty()){
  298. return failed(null, "请传入数据ID");
  299. }
  300. EmsProdplanYear tv = emsProdplanYearService.getById(m.getNo());
  301. if (tv == null){
  302. return failed(null, "数据已经删除,请重新查询数据");
  303. }
  304. }
  305. } else {
  306. return failed(null, "请输入要删除的数据");
  307. }
  308. for (int i = 0; i< models.length; i++) {
  309. emsProdplanYearService.delete(models[i].getId());
  310. }
  311. return success();
  312. }
  313. // //年计划 炼钢厂获取编辑页面
  314. // @ApiOperation(value = "查询",notes = "根据时间来生成数据")
  315. // @ApiImplicitParams({
  316. // @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  317. // @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  318. // })
  319. // @GetMapping(value = "/getDateEditForPage")
  320. // public RESTfulResult getDateEditForPage(@RequestParam HashMap<String, Object> parmas,Integer pageNum, Integer pageSize){
  321. // if(parmas.get("parentid") == null){
  322. // return failed(null, "请选择工序站所");
  323. // }
  324. // if(parmas.get("yearmonth")==null || parmas.get("yearmonth")==null){
  325. // return failed(null, "请选择生成时间");
  326. // }
  327. // try {
  328. // Date end = new SimpleDateFormat("yyyy-MM-dd").parse(parmas.get("jzsj").toString());
  329. // Date start = new SimpleDateFormat("yyyy-MM-dd").parse(parmas.get("cjsj").toString());
  330. // if ((end.getTime()-start.getTime()) / (24 * 60 * 60 * 1000) > 366){
  331. // return failed(null, "生成时间跨度不得超过1年");
  332. // }
  333. // } catch (ParseException e) {
  334. // return failed(null, "时间格式错误");
  335. // }
  336. // PageList<Map<String, Object>> list = emsProdplanYearService.getDateEditForPage(parmas, pageNum, pageSize);
  337. // if(list == null) {
  338. // return failed(null, "日期格式有误");
  339. // }
  340. // return success(list);
  341. // }
  342. @PutMapping(value = "/batchupdateList", produces = "application/json;charset=UTF-8")
  343. public RESTfulResult updateList(@RequestBody EmsProdplanYear[] models) {
  344. String userId = JwtUtil.getUseridByToken();
  345. for (int i = 0; i < models.length; i++) {
  346. EmsProdplanYear model = models[i];
  347. if (model.getNo() == null || model.getNo().equals("")) {
  348. return failed(null, "id为空");
  349. }
  350. if (model.getParentid() == null || model.getNo().equals("")) {
  351. return failed(null, "parentid为空");
  352. }
  353. // 因为一行数据由多条数据组成,所以这里为了确保数据准确性,应该再根据编号查询一次新的数据
  354. EmsProdplanYear emsProdplanYear = emsProdplanYearService.getById(model.getNo());
  355. Calendar c = Calendar.getInstance();
  356. int dayMax = 0;
  357. try {
  358. dayMax = emsProdplanYearService.getDaysOfMonth(emsProdplanYear.getYearmonth());
  359. } catch (ParseException e) {
  360. e.printStackTrace();
  361. }
  362. Integer sumWeight = 0;
  363. EmsProdplanMonth maxSqno = emsProdplanMonthService.getMaxSqno();
  364. String unit = "008";
  365. String productid = "";
  366. String workProcid = "";
  367. Double days = Double.valueOf(dayMax);
  368. switch (model.getParentid()) {
  369. case "LG":
  370. sumWeight = model.getWeight().intValue();
  371. productid="方坯";
  372. if (model.getLine().equals("AT2007-1")){
  373. productid="异型坯";
  374. }
  375. unit="008";
  376. workProcid = "AT2004";
  377. break;
  378. case "LT":
  379. sumWeight = model.getWeight().intValue();
  380. productid="生铁";
  381. unit="008";
  382. days -= 0.5;
  383. break;
  384. case "SJ":
  385. sumWeight = model.getWeight().intValue();
  386. productid="烧结矿";
  387. unit="008";
  388. break;
  389. case "ZG" :
  390. sumWeight = model.getWeight().intValue();
  391. productid="线材";
  392. if(model.getLine().equals("AT2007")) {
  393. productid="H型钢";
  394. }
  395. unit="008";
  396. break;
  397. case "FDC" :
  398. sumWeight = model.getWeight().intValue();
  399. productid="发电量";
  400. // 发电厂合计
  401. //workProcid = "AT1006";
  402. unit="006";
  403. break;
  404. case "JCS" :
  405. sumWeight = model.getWeight().intValue();
  406. productid="白灰粉";
  407. unit="008";
  408. break;
  409. case "JCW" :
  410. sumWeight = model.getWeight().intValue();
  411. productid="矿渣粉";
  412. unit="008";
  413. workProcid = model.getProductid();
  414. break;
  415. case "JJZ" :
  416. sumWeight = model.getWeight1().intValue() + model.getWeight2().intValue() - model.getWeight().intValue();
  417. productid="焦炭";
  418. unit="008";
  419. workProcid = "AT1007";
  420. break;
  421. case "JJF" :
  422. // sumWeight = model.getWeight().intValue();
  423. // productid="焦油";
  424. // if(model.getLine().equals("AT3009")){
  425. // productid="粗苯";
  426. // }
  427. // if(model.getLine().equals("AT3010")){
  428. // productid="硫铵";
  429. // }
  430. // unit="008";
  431. // //workProcid = "AT1007";
  432. // break;
  433. sumWeight = model.getWeight().intValue();
  434. if(model.getLine().equals("AT3009")) {
  435. productid = "粗苯";
  436. //workProcid = "AT2011";
  437. workProcid = "AT3009";
  438. }
  439. if (model.getLine().equals("AT3024")){
  440. productid="焦油";
  441. workProcid = "AT3024";
  442. }
  443. if(model.getLine().equals("AT3010")){
  444. productid="硫铵";
  445. workProcid = "AT3010";
  446. }
  447. if(model.getLine().equals("AT3025")){
  448. productid="硫酸";
  449. workProcid = "AT3025";
  450. }
  451. if(model.getLine().equals("AT2012")){
  452. productid="精煤";
  453. workProcid = "AT2012";
  454. }
  455. unit="008";
  456. break;
  457. default: break;
  458. }
  459. int[] avgWeight = emsProdplanYearService.avgWeight(sumWeight,dayMax, days);
  460. for (int k = 0;k < dayMax;k++) {
  461. EmsProdplanMonth monModel = new EmsProdplanMonth();
  462. c.setTime(model.getYearmonth());
  463. c.add(Calendar.DATE, k);
  464. monModel.setMay(c.getTime());
  465. monModel.setUnit(unit);
  466. monModel.setProductid(productid);
  467. monModel.setWeightMonth(model.getWeight());
  468. if (workProcid.equals("")) {
  469. monModel.setWorkprocid(model.getLine());
  470. } else {
  471. monModel.setWorkprocid(workProcid);
  472. monModel.setWeightMonth(BigDecimal.valueOf(sumWeight));
  473. }
  474. monModel.setWeightOrigin(BigDecimal.valueOf(avgWeight[k]));
  475. monModel.setWeightDay(BigDecimal.valueOf(avgWeight[k]));
  476. monModel.setKxf_weight(BigDecimal.valueOf(avgWeight[k]));
  477. monModel.setYxf_weight(BigDecimal.valueOf(0));
  478. monModel.setJxdays("0");
  479. monModel.setMemo("根据年计划,系统自动生成。");
  480. monModel.setCreateman("系统");
  481. monModel.setCreatetime(new Date());
  482. monModel.setSqno(maxSqno.getSqno()+k);
  483. Map monMap = new HashMap();
  484. monMap.put("may",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
  485. monMap.put("workprocid","'"+monModel.getWorkprocid()+"'");
  486. monMap.put("productid",monModel.getProductid());
  487. monMap.put("startTime",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
  488. monMap.put("endTime",new SimpleDateFormat("yyyy-MM-dd").format(monModel.getMay()));
  489. List<EmsProdplanMonth> monList = emsProdplanMonthMapper.selectByParameters(monMap);
  490. if(monList.size()<=0){
  491. emsProdplanMonthService.add(monModel);
  492. } else {
  493. if((model.getParentid().equals("LG")&&monModel.getProductid().equals("方坯")) || model.getParentid().equals("JJZ")) {
  494. //|| model.getParentid().equals("FDC")
  495. if (i == 0){
  496. monList.get(0).setWeightMonth(BigDecimal.valueOf(0));
  497. monList.get(0).setWeightDay(BigDecimal.valueOf(0));
  498. monList.get(0).setWeightOrigin(BigDecimal.valueOf(0));
  499. }
  500. //monModel.setKxf_weight(monList.get(0).getKxf_weight().add(monModel.getKxf_weight()));
  501. monModel.setWeightMonth(monList.get(0).getWeightMonth().add(monModel.getWeightMonth()));
  502. monModel.setWeightDay(monList.get(0).getWeightDay().add(monModel.getWeightDay()));
  503. monModel.setWeightOrigin(monList.get(0).getWeightOrigin().add(monModel.getWeightOrigin()));
  504. monModel.setId(monList.get(0).getId());
  505. emsProdplanMonthService.modify(monModel);
  506. } else {
  507. monModel.setId(monList.get(0).getId());
  508. emsProdplanMonthService.modify(monModel);
  509. }
  510. }
  511. }
  512. emsProdplanYear.setWeight(model.getWeight());
  513. emsProdplanYear.setWeight1(model.getWeight1());
  514. emsProdplanYear.setWeight2(model.getWeight2());
  515. emsProdplanYear.setMemo(model.getMemo());
  516. emsProdplanYear.setXgr(userId);
  517. emsProdplanYear.setXgsj(new Date());
  518. emsProdplanYearMapper.updateByPrimaryKey(emsProdplanYear);
  519. }
  520. return success();
  521. }
  522. @PutMapping(value = "/batchupdate", produces = "application/json;charset=UTF-8")
  523. public RESTfulResult update(@RequestBody EmsProdplanYear[] models){
  524. String userId = JwtUtil.getUseridByToken();
  525. for (int i = 0; i< models.length; i++) {
  526. EmsProdplanYear model = models[i];
  527. if(model.getNo() == null || model.getNo().equals("")) {
  528. return failed(null,"id为空");
  529. }
  530. if(model.getParentid() == null || model.getNo().equals("")){
  531. return failed(null,"parentid为空");
  532. }
  533. model.setXgr(userId);
  534. model.setXgsj(new Date());
  535. emsProdplanYearMapper.updateByPrimaryKey(model);
  536. }
  537. // if(!failmsg.isEmpty()){
  538. // return failed(null, "序号 [" + failmsg.substring(0, failmsg.length()-1) + "] 已审核,不允许修改");
  539. // }
  540. // for (int i = 0; i< models.length; i++) {
  541. // EmsProdplanYear model = models[i];
  542. // if(model.getCjsj() == null || model.getJzsj() == null){
  543. // return failed(null, "数据请传入时间");
  544. // }
  545. // if(model.getLine() == null || model.getLine().isEmpty()){
  546. // return failed(null, "数据请传入位置");
  547. // }
  548. // if(model.getWeight() == null || model.getWeight() == null){
  549. // return failed(null, "请填写完整数据");
  550. // }
  551. // String strDateFormat = "yyyy-MM-dd";
  552. // SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
  553. // Map map = new HashMap();
  554. // map.put("line",model.getLine());
  555. // map.put("cjsj",sdf.format(model.getCjsj()));
  556. // map.put("jzsj",sdf.format(model.getJzsj()));
  557. // EmsProdplanYear byId = emsProdplanYearService.getByParams(map);
  558. // if(model.getNo() != null && !model.getNo().equals("")){
  559. // model.setXgr(userId);
  560. // model.setXgsj(new Date());
  561. // emsProdplanYearMapper.updateByPrimaryKey(model);
  562. // }
  563. // else if(byId != null && byId.getZt().equals("1")){
  564. // return failed(null, ""+byId.getLine()+"在该期间数据已经生成,无法再次生成");
  565. // }
  566. // else {
  567. // model.setCjr(userId);
  568. // model.setCjsj(new Date());
  569. // model.setZt("1");
  570. // model.setCjr(userId);
  571. // emsProdplanYearService.add(model);
  572. // }
  573. // }
  574. return success();
  575. }
  576. /**
  577. * @MethodName excelimport
  578. * @Author Shadow
  579. * @Description 导入文件
  580. * @Date 2021/12/30 15:20
  581. **/
  582. @PostMapping(value = "excelimport")
  583. public RESTfulResult excelimport(@RequestParam("file") MultipartFile file) throws Exception {
  584. RESTfulResult rs= null;
  585. try {
  586. if(file.isEmpty()){
  587. return failed(null,"上传失败,请选择文件");
  588. }
  589. String fileNmae = file.getOriginalFilename();
  590. File files = ExcelToolUtils.multipartFileToFile(file);
  591. rs = emsProdplanYearService.insertexcel(files);
  592. ExcelToolUtils.delteTempFile(files);
  593. } catch (Exception e){
  594. e.printStackTrace();
  595. rs.setCode("500");
  596. rs.setMessage("服务端异常!");
  597. }finally {
  598. }
  599. return rs;
  600. }
  601. }