BusinessAgentBgzzController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.chinaitop.depot.agent.bgz.controller;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import javax.annotation.Resource;
  6. import org.springframework.http.MediaType;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestMethod;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgzz;
  11. import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgzzExample;
  12. import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgzzExample.Criteria;
  13. import com.chinaitop.depot.agent.bgz.service.BusinessAgentBgzzService;
  14. import com.chinaitop.utils.ParameterUtil;
  15. import com.fasterxml.jackson.databind.ObjectMapper;
  16. import com.github.pagehelper.PageHelper;
  17. import com.github.pagehelper.PageInfo;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiImplicitParam;
  20. import io.swagger.annotations.ApiImplicitParams;
  21. import io.swagger.annotations.ApiOperation;
  22. @RestController
  23. @RequestMapping(value = "/agent_bgzz")
  24. @Api(description = "代储库保管总账控制类")
  25. public class BusinessAgentBgzzController {
  26. @Resource
  27. private BusinessAgentBgzzService bgzzService;
  28. @RequestMapping(value = "/getList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  29. @ApiOperation(value="代储库分仓保管账信息列表", notes = "代储库分仓保管账信息列表")
  30. @ApiImplicitParams({
  31. @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
  32. @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
  33. @ApiImplicitParam(name = "bgzzJson", value = "条件对象", paramType = "query")
  34. })
  35. public PageInfo<BusinessAgentBgzz> list(Integer pageNum, Integer pageSize, String bgzzJson) {
  36. ObjectMapper mapper = new ObjectMapper();
  37. BusinessAgentBgzz bgzz = null;
  38. try {
  39. bgzz = (BusinessAgentBgzz) mapper.readValue(bgzzJson, BusinessAgentBgzz.class);
  40. } catch (Exception e) {
  41. e.printStackTrace();
  42. }
  43. BusinessAgentBgzzExample example = new BusinessAgentBgzzExample();
  44. Criteria criteria = example.createCriteria();
  45. /* orgId */
  46. if(ParameterUtil.isnotnull(bgzz.getOrgId())){
  47. criteria.andAgentIdEqualTo(bgzz.getOrgId());
  48. }
  49. /* 代储点ID */
  50. if(ParameterUtil.isnotnull(bgzz.getAgentId())){
  51. criteria.andAgentIdEqualTo(bgzz.getAgentId());
  52. }
  53. /* 代储库ID */
  54. if(ParameterUtil.isnotnull(bgzz.getDckId())){
  55. criteria.andDckIdEqualTo(bgzz.getDckId());
  56. }
  57. /* 粮食品种ID */
  58. if(ParameterUtil.isnotnull(bgzz.getLspz())){
  59. criteria.andLspzEqualTo(bgzz.getLspz());
  60. }
  61. /* 粮食性质ID */
  62. if(ParameterUtil.isnotnull(bgzz.getLsxz())){
  63. criteria.andLsxzEqualTo(bgzz.getLsxz());
  64. }
  65. /* 业务月份 */
  66. if(ParameterUtil.isnotnull(bgzz.getFssj())){
  67. criteria.andFssjEqualTo(bgzz.getFssj());
  68. }
  69. /* 分页 */
  70. if(ParameterUtil.isnotnull(pageNum) && ParameterUtil.isnotnull(pageSize)){
  71. PageHelper.startPage(pageNum, pageSize);
  72. }
  73. List<BusinessAgentBgzz> list = bgzzService.findByConditions(example);
  74. PageInfo<BusinessAgentBgzz> pageInfo = new PageInfo<BusinessAgentBgzz>(list);
  75. return pageInfo;
  76. }
  77. @RequestMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  78. @ApiOperation(value="新增或修改代储库保管总账信息", notes = "新增或修改代储库保管总账信息")
  79. @ApiImplicitParams({
  80. @ApiImplicitParam(name = "bgzzJson", value = "数据对象", paramType = "form"),
  81. @ApiImplicitParam(name = "type", value = "操作类型", paramType = "form")
  82. })
  83. public Map<String, Object> edit(String bgzzJson, String type) {
  84. Map<String, Object> modelMap = new HashMap<String, Object>();
  85. // JSON字符串转对象
  86. ObjectMapper mapper = new ObjectMapper();
  87. try {
  88. BusinessAgentBgzz bgzz = (BusinessAgentBgzz) mapper.readValue(bgzzJson, BusinessAgentBgzz.class);
  89. if (type != null && "shenhe".equals(type)) {
  90. bgzzService.update(bgzz);
  91. } else {
  92. /**
  93. * 实现思路:
  94. * 1、查询是否记过账
  95. * 2、如果记过账则直接修改数据就行,否则就新增记账数据
  96. */
  97. BusinessAgentBgzzExample example = new BusinessAgentBgzzExample();
  98. Criteria criteria = example.createCriteria();
  99. /* orgId */
  100. if(ParameterUtil.isnotnull(bgzz.getOrgId())){
  101. criteria.andOrgIdEqualTo(bgzz.getOrgId());
  102. }
  103. /* 代储点ID */
  104. if(ParameterUtil.isnotnull(bgzz.getAgentId())){
  105. criteria.andAgentIdEqualTo(bgzz.getAgentId());
  106. }
  107. /* 代储库ID */
  108. if(ParameterUtil.isnotnull(bgzz.getDckId())){
  109. criteria.andDckIdEqualTo(bgzz.getDckId());
  110. }
  111. /* 粮食品种ID */
  112. if(ParameterUtil.isnotnull(bgzz.getLspz())){
  113. criteria.andLspzEqualTo(bgzz.getLspz());
  114. }
  115. /* 粮食性质ID */
  116. if(ParameterUtil.isnotnull(bgzz.getLsxz())){
  117. criteria.andLsxzEqualTo(bgzz.getLsxz());
  118. }
  119. /* 业务月份 */
  120. if(ParameterUtil.isnotnull(bgzz.getFssj())){
  121. criteria.andFssjEqualTo(bgzz.getFssj());
  122. }
  123. List<BusinessAgentBgzz> list = bgzzService.findByConditions(example);
  124. if (null != list && list.size() > 0) {
  125. bgzzService.update(bgzz);
  126. } else {
  127. bgzzService.insert(bgzz);
  128. }
  129. }
  130. modelMap.put("status", "success");
  131. modelMap.put("msg", "操作成功!");
  132. } catch (Exception e) {
  133. e.printStackTrace();
  134. modelMap.put("status", "error");
  135. modelMap.put("msg", "操作失败!");
  136. }
  137. return modelMap;
  138. }
  139. }