EmsProdplanRoundController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. package com.steerinfo.ems.emsprodplanround.controller;
  2. import com.steerinfo.auth.utils.JwtUtil;
  3. import com.steerinfo.ems.Utils.DateUtils;
  4. import com.steerinfo.ems.emsgmpcjh.mapper.EmsGmPcJhMapper;
  5. import com.steerinfo.ems.emsgmpcjh.model.EmsGmPcJh;
  6. import com.steerinfo.ems.emslog.mapper.EmsLogMapper;
  7. import com.steerinfo.ems.emslog.model.EmsLog;
  8. import com.steerinfo.ems.emslog.service.IEmsLogService;
  9. import com.steerinfo.ems.emsprodplanmonth.mapper.EmsProdplanMonthMapper;
  10. import com.steerinfo.ems.emsprodplanmonth.model.EmsProdplanMonth;
  11. import com.steerinfo.ems.emsprodplanmonth.service.IEmsProdplanMonthService;
  12. import com.steerinfo.ems.emsprodplanround.mapper.EmsProdplanRoundMapper;
  13. import com.steerinfo.ems.emsprodplanweightadjustment.model.EmsProdplanWeightAdjustment;
  14. import com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear;
  15. import com.steerinfo.framework.controller.BaseRESTfulController;
  16. import com.steerinfo.framework.controller.RESTfulResult;
  17. import com.steerinfo.framework.service.pagehelper.PageList;
  18. import com.steerinfo.framework.utils.collection.ListUtils;
  19. import com.steerinfo.ems.emsprodplanround.model.EmsProdplanRound;
  20. import com.steerinfo.ems.emsprodplanround.service.IEmsProdplanRoundService;
  21. import com.steerinfo.framework.utils.misc.IdGenerator;
  22. import io.swagger.annotations.ApiImplicitParam;
  23. import io.swagger.annotations.ApiImplicitParams;
  24. import io.swagger.annotations.ApiOperation;
  25. import lombok.val;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.apache.shiro.authz.annotation.RequiresPermissions;
  28. import org.apache.tools.ant.taskdefs.Get;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import org.springframework.web.bind.annotation.*;
  32. import java.text.SimpleDateFormat;
  33. import java.util.*;
  34. import java.math.BigDecimal;
  35. import java.util.stream.Collectors;
  36. /**
  37. * EmsProdplanRound RESTful接口:
  38. * @author generator
  39. * @version 1.0-SNAPSHORT 2021-07-06 03:43
  40. * 类描述
  41. * 修订历史:
  42. * 日期:2021-07-06
  43. * 作者:generator
  44. * 参考:
  45. * 描述:EmsProdplanRound RESTful接口
  46. * @see null
  47. * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  48. */
  49. @RestController
  50. @RequestMapping("/${api.version}/emsprodplanrounds")
  51. public class EmsProdplanRoundController extends BaseRESTfulController {
  52. @Autowired
  53. IEmsProdplanRoundService emsProdplanRoundService;
  54. @Autowired
  55. EmsGmPcJhMapper emsGmPcJhMapper;
  56. @Autowired
  57. EmsProdplanRoundMapper emsProdplanRoundMapper;
  58. @Autowired
  59. IEmsProdplanMonthService emsProdplanMonthService;
  60. @Autowired
  61. IEmsLogService emsLogService;
  62. @Autowired
  63. IdGenerator idGenerator;
  64. @ApiOperation(value="获取列表", notes="分页查询")
  65. @ApiImplicitParams({
  66. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  67. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  68. })
  69. //@RequiresPermissions("emsprodplanround:view")
  70. @GetMapping(value = "/")
  71. public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  72. PageList<EmsProdplanRound> list = emsProdplanRoundService.queryForPage(parmas, pageNum, pageSize);
  73. return success(list);
  74. }
  75. @ApiOperation(value="获取列表", notes="分页模糊查询")
  76. @ApiImplicitParams({
  77. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  78. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  79. })
  80. //@RequiresPermissions("emsprodplanround:view")
  81. @GetMapping(value = "/like/")
  82. public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
  83. PageList<EmsProdplanRound> list = emsProdplanRoundService.queryLikeForPage(parmas, pageNum, pageSize);
  84. return success(list);
  85. }
  86. @ApiOperation(value="创建", notes="根据EmsProdplanRound对象创建")
  87. @ApiImplicitParam(name = "emsProdplanRound", value = "详细实体emsProdplanRound", required = true, dataType = "EmsProdplanRound")
  88. @PostMapping(value = "/")
  89. public RESTfulResult add(@RequestBody EmsProdplanRound [] models){
  90. String userId = JwtUtil.getUseridByToken();
  91. String maxid = null;
  92. for (EmsProdplanRound model : models) {
  93. if (model.getParentid() == null ){
  94. return failed(null,"请点击选择左边计划!!!");
  95. }
  96. EmsGmPcJh emsGmPcJh = emsGmPcJhMapper.selectByPrimaryKey(model.getParentid());
  97. if(emsGmPcJh.getState().equals("0")){
  98. return failed(null,"排产计划编号为"+emsGmPcJh.getId()+"做了取消下发操作,无法做新增操作");
  99. }
  100. if(model.getWorkprocType() == null || model.getWorkprocType().equals("")){
  101. return failed(null,"工序或者时间为空");
  102. }
  103. if (model.getParentid().substring(0,1).equals("G")){
  104. maxid = emsProdplanRoundService.getMaxidAsGm(model);
  105. model.setAscription("0");
  106. }
  107. else {
  108. maxid = emsProdplanRoundService.getMaxidAsSC(model);
  109. model.setAscription("1");
  110. }
  111. model.setId(maxid);
  112. model.setPlanWeight(model.getPlanWeight());
  113. model.setMsgFlag("I");
  114. model.setReadFlag("N");
  115. model.setState("0");
  116. model.setCreatetime(new Date());
  117. model.setCreateman(userId);
  118. model.setWorkprocType(model.getWorkprocType());
  119. emsProdplanRoundService.add(model);
  120. emsGmPcJh.setState("3");
  121. emsGmPcJh.setReceiveTime(new Date());
  122. emsGmPcJhMapper.updateByPrimaryKeySelective(emsGmPcJh);
  123. }
  124. return success();
  125. }
  126. // @PutMapping(value = "/batchupdate", produces = "application/json;charset=UTF-8")
  127. // public RESTfulResult batchupdate(@RequestBody EmsProdplanRound [] models ){
  128. // String userId = JwtUtil.getUseridByToken();
  129. // for (int i = 0; i < models.length; i++) {
  130. // EmsProdplanRound model = models[i];
  131. // HashMap<String,Object> map = new HashMap();
  132. // String strDateFormat = "yyyy-MM";
  133. // SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
  134. // map.put("id",model.getParentid());
  135. // map.put("may",sdf.format(model.getMay()));
  136. // EmsProdplanMonth emsProdplanMonth = emsProdplanMonthMapper.getBymayAndWorkprocid(map);
  137. // Long weightMonth = emsProdplanMonth.getWeightMonth();
  138. // Long kxf_weight = emsProdplanMonth.getKxf_weight();
  139. // Long yxf_weight = emsProdplanMonth.getYxf_weight();
  140. // yxf_weight = model.getPlanWeight()+yxf_weight;
  141. // kxf_weight = weightMonth-yxf_weight;
  142. // if(yxf_weight>weightMonth){
  143. // return failed(null,"可下发重量不足");
  144. // }
  145. // emsProdplanMonth.setKxf_weight(kxf_weight);
  146. // emsProdplanMonth.setYxf_weight(yxf_weight);
  147. // emsProdplanMonthMapper.updateByPrimaryKey(emsProdplanMonth);
  148. // emsProdplanRoundMapper.updateByPrimaryKey(model);
  149. // }
  150. // return success();
  151. // }
  152. @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
  153. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  154. //@RequiresPermissions("emsprodplanround:view")
  155. @GetMapping(value = "/{id}")
  156. public RESTfulResult get(@PathVariable String id){
  157. EmsProdplanRound emsProdplanRound = emsProdplanRoundService.getById(id);
  158. return success(emsProdplanRound);
  159. }
  160. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsProdplanRound信息来更新详细信息")
  161. @ApiImplicitParams({
  162. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  163. @ApiImplicitParam(name = "emsProdplanRound", value = "详细实体emsProdplanRound", required = true, dataType = "EmsProdplanRound")
  164. })
  165. //@RequiresPermissions("emsprodplanround:update")
  166. @PutMapping(value = "batchUpdate", produces = "application/json;charset=UTF-8")
  167. public RESTfulResult update(@RequestBody EmsProdplanRound[] models){
  168. String userId = JwtUtil.getUseridByToken();
  169. for (int i = 0; i < models.length; i++) {
  170. EmsProdplanRound model = models[i];
  171. if(model.getState().equals("1") || model.getState().equals("2")){
  172. return failed(null,"存在已经下发或者审核的计划,无法做修改");
  173. }
  174. model.setUpdateman(userId);
  175. model.setUpdatetime(new Date());
  176. emsProdplanRoundMapper.updateByPrimaryKey(model);
  177. }
  178. return success();
  179. }
  180. @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsProdplanRound信息来更新详细信息")
  181. @ApiImplicitParams({
  182. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
  183. @ApiImplicitParam(name = "emsProdplanRound", value = "详细实体emsProdplanRound", required = true, dataType = "EmsProdplanRound")
  184. })
  185. //@RequiresPermissions("emsprodplanround:update")
  186. @PutMapping(value = "ForcedUpdate", produces = "application/json;charset=UTF-8")
  187. public RESTfulResult ForcedUpdate(@RequestBody EmsProdplanRound[] models) {
  188. String userId = JwtUtil.getUseridByToken();
  189. EmsLog emsLog = new EmsLog();
  190. for (int i = 0; i < models.length; i++) {
  191. EmsProdplanRound model = models[i];
  192. model.setUpdateman(userId);
  193. model.setUpdatetime(new Date());
  194. String str = "{修改前的数据为:"+emsProdplanRoundMapper.selectByPrimaryKey(model.getId())+"修改后的数据为:"+model+"}";
  195. emsProdplanRoundMapper.updateByPrimaryKey(model);
  196. emsLog.setCode(str);
  197. emsLog.setOperator(userId);
  198. emsLog.setUpdatetable("ems_prodplan_round");
  199. emsLog.setOperatortime(new Date());
  200. emsLog.setId(idGenerator.getNextStr());
  201. emsLogService.add(emsLog);
  202. }
  203. return success();
  204. }
  205. @ApiOperation(value="删除", notes="根据url的id来指定删除对象")
  206. @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
  207. //@RequiresPermissions("emsprodplanround:delete")
  208. @DeleteMapping(value = "/{id}")
  209. public RESTfulResult delete(@PathVariable String id ,@RequestBody EmsProdplanRound[] models){
  210. List<String> list = Arrays.asList(id.split(","));
  211. if(ListUtils.isNotEmpty(list)) {
  212. List<String> ids = ListUtils.convertList(list);
  213. emsProdplanRoundService.delete(ids);
  214. }
  215. return success();
  216. }
  217. @ApiOperation(value="下发", notes="根据models修改对象")
  218. @ApiImplicitParam(name = "emsProdplanRounds", value = "", required = true, dataType = "EmsProdplanRounds")
  219. @PostMapping(value = "/issue")
  220. @Transactional
  221. public RESTfulResult issue(@RequestBody EmsProdplanRound [] models){
  222. List id = new ArrayList();
  223. String monthid = "";
  224. for (int i = 0; i < models.length; i++) {
  225. EmsProdplanRound model = models[i];
  226. id.add(model.getId());
  227. monthid = model.getParentid();
  228. model.setIssuedTime(new Date());
  229. if(model.getState().equals("1")){
  230. return failed(null,"存在已下发的计划,无法再次做下发");
  231. }
  232. if (model.getState().equals("3")) {
  233. return failed(null,"存在审核不通过的计划, 无法下发");
  234. }
  235. model.setState("1");
  236. emsProdplanRoundMapper.updateByPrimaryKey(model);
  237. }
  238. EmsProdplanRound sumPlanWeight = emsProdplanRoundService.getSumPlanWeight(id);
  239. EmsGmPcJh emsGmPcJh = emsGmPcJhMapper.selectByPrimaryKey(monthid);
  240. emsGmPcJh.setKxfWeight(emsGmPcJh.getPlanWeight().subtract(emsGmPcJh.getYxfWeight().add(sumPlanWeight.getPlanWeight())));
  241. emsGmPcJh.setYxfWeight(emsGmPcJh.getYxfWeight().add(sumPlanWeight.getPlanWeight()));
  242. emsGmPcJhMapper.updateByPrimaryKey(emsGmPcJh);
  243. return success();
  244. }
  245. @ApiOperation(value="取消下发", notes="根据models修改对象")
  246. @ApiImplicitParam(name = "emsProdplanRounds", value = "", required = true, dataType = "EmsProdplanRounds")
  247. @PostMapping(value = "/offissue")
  248. @Transactional
  249. public RESTfulResult offissue(@RequestBody EmsProdplanRound [] models){
  250. List id = new ArrayList();
  251. String monthid = "";
  252. String state ="";
  253. for (int i = 0; i < models.length; i++) {
  254. EmsProdplanRound model = models[i];
  255. id.add(model.getId());
  256. monthid = model.getParentid();
  257. model.setIssuedTime(new Date());
  258. if(model.getState().equals("0")){
  259. return failed(null,"没有下发过的轮次计划无法做取消下发操作");
  260. }
  261. EmsProdplanRound emsProdplanRound = emsProdplanRoundMapper.selectByPrimaryKey(model.getId());
  262. if(emsProdplanRound.getState().equals("2")){
  263. return failed(null,"存在已经接收的计划,无法做取消下发操作,请重新刷新页面");
  264. }
  265. model.setState("0");
  266. emsProdplanRoundMapper.updateByPrimaryKey(model);
  267. }
  268. EmsProdplanRound sumPlanWeight = emsProdplanRoundService.getSumPlanWeight(id);
  269. EmsGmPcJh emsGmPcJh = emsGmPcJhMapper.selectByPrimaryKey(monthid);
  270. // 取消下发操作
  271. emsGmPcJh.setKxfWeight(emsGmPcJh.getKxfWeight().add(sumPlanWeight.getPlanWeight()));
  272. emsGmPcJh.setYxfWeight(emsGmPcJh.getYxfWeight().subtract(sumPlanWeight.getPlanWeight()));
  273. emsGmPcJhMapper.updateByPrimaryKey(emsGmPcJh);
  274. return success();
  275. }
  276. @ApiImplicitParam(name = "emsProdplanRounds", value = "", required = true, dataType = "EmsProdplanRounds")
  277. @PostMapping(value = "/delete")
  278. public RESTfulResult delete(@RequestBody EmsProdplanRound [] models){
  279. for (int i = 0; i < models.length; i++) {
  280. EmsProdplanRound model = models[i];
  281. if (model.getState().equals("1") || model.getState().equals("2")) {
  282. return failed(null, "数据已下发或者被接收,无法删除");
  283. }
  284. emsProdplanRoundMapper.deleteByPrimaryKey(model.getId());
  285. updateNbjh(model);
  286. }
  287. return success();
  288. }
  289. @ApiOperation(value="获取详细信息", notes="根据url获取长度*宽度")
  290. @GetMapping(value = "getbasespecbillet")
  291. public RESTfulResult getlengthTimesWidth(){
  292. List<EmsProdplanRound> emsProdplanRounds = emsProdplanRoundService.getbasespecbillet();
  293. return success(emsProdplanRounds);
  294. }
  295. @ApiOperation(value="获取详细信息", notes="根据url获取断面")
  296. @GetMapping(value = "getiateralArea")
  297. public RESTfulResult getiateralArea(){
  298. List<EmsProdplanRound> emsProdplanRounds = emsProdplanRoundService.getiateralArea();
  299. return success(emsProdplanRounds);
  300. }
  301. @ApiOperation(value="获取详细信息", notes="根据url获取截取面积")
  302. @GetMapping(value = "getdimension")
  303. public RESTfulResult getdimension(){
  304. List<EmsProdplanRound> emsProdplanRounds = emsProdplanRoundService.getdimension();
  305. return success(emsProdplanRounds);
  306. }
  307. @ApiOperation(value="获取详细信息", notes="根据url获取断面")
  308. @GetMapping(value = "getsurfaceStandard")
  309. public RESTfulResult getsurfaceStandard(){
  310. List<EmsProdplanRound> emsProdplanRounds = emsProdplanRoundService.getsurfaceStandard();
  311. return success(emsProdplanRounds);
  312. }
  313. public void updateNbjh(EmsProdplanRound emsProdplanRound) {
  314. if (emsProdplanRound.getParentid() != null || !emsProdplanRound.getParentid().equals("")) {
  315. Map<String,Object> map = new HashMap();
  316. map.put("parentid",emsProdplanRound.getParentid());
  317. List list = emsProdplanRoundMapper.selectByParameters(map);
  318. if (list.size()<1) {
  319. EmsGmPcJh emsGmPcJh = emsGmPcJhMapper.selectByPrimaryKey(emsProdplanRound.getParentid());
  320. emsGmPcJh.setState("2");
  321. emsGmPcJhMapper.updateByPrimaryKeySelective(emsGmPcJh);
  322. }
  323. }
  324. }
  325. @ApiOperation(value="获取列表", notes="审核页面分页查询")
  326. @ApiImplicitParams({
  327. @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
  328. @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
  329. })
  330. //@RequiresPermissions("emsprodplanround:view")
  331. @GetMapping(value = "/getAuditDate")
  332. //获取未审核的数据
  333. public RESTfulResult getAuditDateForPage (@RequestParam HashMap parmas,Integer pageNum, Integer pageSize) {
  334. PageList list = emsProdplanRoundService.getAuditDateForPage(parmas, pageNum, pageSize);
  335. return success(list);
  336. }
  337. @ApiOperation(value="获取列表", notes="审核页面修改")
  338. @PutMapping(value = "updateAuditState", produces = "application/json;charset=UTF-8")
  339. public RESTfulResult updateAuditState(@RequestBody EmsProdplanRound[] models){
  340. for (int i = 0; i < models.length; i++) {
  341. EmsProdplanRound model = models[i];
  342. if(model.getState().equals("2")){
  343. return failed(null,"操作失败,存在已经下发或者接收的计划");
  344. }
  345. EmsProdplanRound emsProdplanRound = emsProdplanRoundMapper.selectByPrimaryKey(model.getId());
  346. if (emsProdplanRound.getAuditState().equals("1")){
  347. return failed(null,"编号为"+model.getId()+"已经再审核中,请勿重复操作");
  348. }
  349. if (emsProdplanRound.getAuditState().equals("2")){
  350. return failed(null,"编号为"+model.getId()+"已经审核通过,请勿重复操作");
  351. }
  352. if(emsProdplanRound.getAuditState().equals("3")){
  353. return failed(null,"编号为"+model.getId()+"审核失败,请勿重复操作");
  354. }
  355. model.setAuditState("1");
  356. emsProdplanRoundService.updateAuditState(model);
  357. }
  358. return success();
  359. }
  360. @ApiOperation(value="修改列表", notes="审核页面修改")
  361. @PutMapping(value = "updateAudit", produces = "application/json;charset=UTF-8")
  362. public RESTfulResult updateAudit(@RequestBody EmsProdplanRound[] models){
  363. for (EmsProdplanRound model : models) {
  364. if (model.getState().equals("2")) {
  365. return failed("操作失败,编号为"+model.getId()+"已经接收");
  366. }
  367. emsProdplanRoundService.updateAuditState(model);
  368. }
  369. return success();
  370. }
  371. @ApiOperation(value="获取子节点", notes="销售订单重量调整")
  372. @GetMapping(value = "/getRounds")
  373. public RESTfulResult getRounds(@RequestParam HashMap parmas){
  374. EmsProdplanRound emsProdplanRound = new EmsProdplanRound();
  375. emsProdplanRound.setParentid(parmas.get("parentid").toString());
  376. List<EmsProdplanRound> rounds = emsProdplanRoundService.getRounds(emsProdplanRound);
  377. Map<String,List<EmsProdplanRound>> stringListMap =
  378. (HashMap<String, List<EmsProdplanRound>>) rounds.stream().collect(
  379. Collectors.groupingBy(EmsProdplanRound::getParentid)
  380. );
  381. List mapList = new ArrayList<>();
  382. //数据,进行组装
  383. mapList.add(stringListMap);
  384. return success(mapList);
  385. }
  386. @PutMapping(value = "/addSave", produces = "application/json;charset=UTF-8")
  387. public RESTfulResult addSave(@RequestBody EmsProdplanRound model){
  388. if (model.getId() != null ) {
  389. EmsProdplanRound emsProdplanRound = emsProdplanRoundMapper.selectByPrimaryKey(model.getId());
  390. emsProdplanRound.setPlanWeight(model.getPlanWeight());
  391. emsProdplanRoundMapper.updateByPrimaryKey(emsProdplanRound);
  392. return success();
  393. }
  394. return failed();
  395. }
  396. @GetMapping("getstdchem")
  397. public RESTfulResult getstdchem(){
  398. List<EmsProdplanRound> emsProdplanRounds = emsProdplanRoundService.getchemicalStandard();
  399. return success(emsProdplanRounds);
  400. }
  401. }