BusinessAgentBgmxzController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. package com.chinaitop.depot.agent.bgz.controller;
  2. import java.io.UnsupportedEncodingException;
  3. import java.lang.reflect.Parameter;
  4. import java.math.BigDecimal;
  5. import java.net.URLEncoder;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import javax.annotation.Resource;
  11. import com.alibaba.fastjson.JSON;
  12. import com.chinaitop.utils.HTTPUtils;
  13. import org.springframework.http.MediaType;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.chinaitop.depot.agent.basic.model.BusinessAgentDepot;
  18. import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgmxz;
  19. import com.chinaitop.depot.agent.bgz.service.BusinessAgentBgmxzService;
  20. import com.chinaitop.utils.ParameterUtil;
  21. import com.fasterxml.jackson.databind.ObjectMapper;
  22. import com.github.pagehelper.PageHelper;
  23. import com.github.pagehelper.PageInfo;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiImplicitParam;
  26. import io.swagger.annotations.ApiImplicitParams;
  27. import io.swagger.annotations.ApiOperation;
  28. import net.sf.json.JSONArray;
  29. import net.sf.json.JSONObject;
  30. @RestController
  31. @RequestMapping(value = "/agent_bgmxz")
  32. @Api(description = "代储库保管明细账控制类")
  33. public class BusinessAgentBgmxzController {
  34. @Resource
  35. private BusinessAgentBgmxzService bgmxzService;
  36. @RequestMapping(value = "/getList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  37. @ApiOperation(value="代储库保管明细账信息列表", notes = "代储库保管明细账信息列表")
  38. @ApiImplicitParams({
  39. @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
  40. @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
  41. @ApiImplicitParam(name = "agentId", value = "代储点ID", paramType = "query"),
  42. @ApiImplicitParam(name = "szlkOrgId", value = "代储库ID", paramType = "query"),
  43. @ApiImplicitParam(name = "houseId", value = "代储库仓房ID", paramType = "query"),
  44. @ApiImplicitParam(name = "wareId", value = "代储库货位id", paramType = "query"),
  45. @ApiImplicitParam(name = "fssj", value = "业务发生时间", paramType = "query"),
  46. @ApiImplicitParam(name = "orgId", value = "单位ID", paramType = "query")
  47. })
  48. public PageInfo<BusinessAgentBgmxz> list(Integer pageNum, Integer pageSize, Integer agentId, Integer szlkOrgId,
  49. Integer houseId, Integer wareId, String fssj, Integer orgId) {
  50. /* 代储点ID */
  51. Map<String, Object> param_map = new HashMap<String, Object>();
  52. if(ParameterUtil.isnotnull(agentId)){
  53. param_map.put("agentId", agentId);
  54. }
  55. /* 代储库ID */
  56. if(ParameterUtil.isnotnull(szlkOrgId)){
  57. param_map.put("szlkOrgId", szlkOrgId);
  58. }
  59. /* 仓房ID */
  60. if(ParameterUtil.isnotnull(houseId)){
  61. param_map.put("houseId", houseId);
  62. }
  63. /* 货位ID */
  64. if(ParameterUtil.isnotnull(wareId)){
  65. param_map.put("wareId", wareId);
  66. }
  67. /* 业务发生时间 */
  68. if(ParameterUtil.isnotnull(fssj)){
  69. Date startTime = ParameterUtil.string2datetime(fssj+" 00:00:00");
  70. Date endTime = ParameterUtil.string2datetime(fssj+" 23:59:59");
  71. param_map.put("startTime", startTime);
  72. param_map.put("endTime", endTime);
  73. }
  74. if (ParameterUtil.isnotnull(orgId)) {
  75. param_map.put("orgId", orgId);
  76. }
  77. /* 排序 */
  78. param_map.put("orderByClause", "a.fssj desc");
  79. /* 分页 */
  80. if(ParameterUtil.isnotnull(pageNum) && ParameterUtil.isnotnull(pageSize)){
  81. PageHelper.startPage(pageNum, pageSize);
  82. }
  83. List<BusinessAgentBgmxz> list = bgmxzService.findByConditions(param_map);
  84. PageInfo<BusinessAgentBgmxz> pageInfo = new PageInfo<BusinessAgentBgmxz>(list);
  85. return pageInfo;
  86. }
  87. @RequestMapping(value = "/findByMxbgz", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  88. @ApiOperation(value="查看代储库保管明细账信息", notes = "查看代储库保管明细账信息")
  89. @ApiImplicitParams({
  90. @ApiImplicitParam(name = "id", value = "数据ID", paramType = "query")
  91. })
  92. public BusinessAgentBgmxz findByMxbgz(Integer id) {
  93. BusinessAgentBgmxz bgmxz = null;
  94. if (null != id) {
  95. bgmxz = bgmxzService.findByParmaryKey(id);
  96. } else {
  97. bgmxz = new BusinessAgentBgmxz();
  98. }
  99. return bgmxz;
  100. }
  101. @RequestMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  102. @ApiOperation(value="新增或修改代储库保管明细账信息", notes = "新增或修改代储库保管明细账信息")
  103. @ApiImplicitParams({
  104. @ApiImplicitParam(name = "bgmxzJson", value = "数据对象", paramType = "form")
  105. })
  106. public Map<String, Object> edit(String bgmxzJson) {
  107. Map<String, Object> modelMap = new HashMap<String, Object>();
  108. // JSON字符串转对象
  109. ObjectMapper mapper = new ObjectMapper();
  110. try {
  111. BusinessAgentBgmxz bgmxz = (BusinessAgentBgmxz) mapper.readValue(bgmxzJson, BusinessAgentBgmxz.class);
  112. if (bgmxz.getId() != null) {
  113. bgmxzService.update(bgmxz);
  114. } else {
  115. bgmxzService.insert(bgmxz);
  116. }
  117. modelMap.put("status", "success");
  118. modelMap.put("msg", "操作成功!");
  119. } catch (Exception e) {
  120. e.printStackTrace();
  121. modelMap.put("status", "error");
  122. modelMap.put("msg", "操作失败!");
  123. }
  124. return modelMap;
  125. }
  126. @RequestMapping(value = "/remove", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  127. @ApiOperation(value="新增或修改代储库保管明细账信息", notes = "新增或修改代储库保管明细账信息")
  128. @ApiImplicitParams({
  129. @ApiImplicitParam(name = "id", value = "数据ID", paramType = "form")
  130. })
  131. public Map<String, Object> remove(Integer id) {
  132. Map<String, Object> modelMap = new HashMap<String, Object>();
  133. try {
  134. if (null != id) {
  135. bgmxzService.remove(id);
  136. modelMap.put("status", "success");
  137. modelMap.put("msg", "操作成功!");
  138. }
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. modelMap.put("status", "error");
  142. modelMap.put("msg", "操作失败!");
  143. }
  144. return modelMap;
  145. }
  146. @RequestMapping(value="/getFcbgzList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  147. @ApiOperation(value="分仓保管列表,按天统计", notes = "分仓保管列表,按天统计,支持分页")
  148. @ApiImplicitParams({
  149. @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"),
  150. @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"),
  151. @ApiImplicitParam(name="bgmxzJson", value="数据对象", paramType="query")
  152. })
  153. public PageInfo<Map<String, Object>> getFcbgzList(Integer pageNum, Integer pageSize, String bgmxzJson) {
  154. Map<String, Object> paramMap = new HashMap<String, Object>();
  155. ObjectMapper mapper = new ObjectMapper();
  156. BusinessAgentBgmxz bgmxz = null;
  157. try {
  158. bgmxz = (BusinessAgentBgmxz) mapper.readValue(bgmxzJson, BusinessAgentBgmxz.class);
  159. } catch (Exception e) {
  160. e.printStackTrace();
  161. }
  162. if(ParameterUtil.isnotnull(bgmxz.getOrgId())){
  163. paramMap.put("orgId", bgmxz.getOrgId());
  164. }
  165. if(ParameterUtil.isnotnull(bgmxz.getAgentId())){
  166. paramMap.put("agentId", bgmxz.getAgentId());
  167. }
  168. if(ParameterUtil.isnotnull(bgmxz.getSzlkOrgId())){
  169. paramMap.put("szlkOrgId", bgmxz.getSzlkOrgId());
  170. }
  171. if(ParameterUtil.isnotnull(bgmxz.getHouseId())){
  172. paramMap.put("houseId", bgmxz.getHouseId());
  173. }
  174. if(ParameterUtil.isnotnull(bgmxz.getWareId())){
  175. paramMap.put("wareId", bgmxz.getWareId());
  176. }
  177. if(ParameterUtil.isnotnull(bgmxz.getLspz())){
  178. paramMap.put("lspz", bgmxz.getLspz());
  179. }
  180. if(ParameterUtil.isnotnull(bgmxz.getLsxz())){
  181. paramMap.put("lsxz", bgmxz.getLsxz());
  182. }
  183. if(ParameterUtil.isnotnull(bgmxz.getFssj())){
  184. paramMap.put("fssj", bgmxz.getFssj());
  185. }
  186. /* 分页 */
  187. if(ParameterUtil.isnotnull(pageNum) && ParameterUtil.isnotnull(pageSize)){
  188. PageHelper.startPage(pageNum, pageSize);
  189. }
  190. List<Map<String, Object>> list = bgmxzService.selectFcbgzList(paramMap);
  191. PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(list);
  192. return pageInfo;
  193. }
  194. @RequestMapping(value="/selectAgentHouseWareList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
  195. @ApiOperation(value="查询代储库正常使用的货位数据信息", notes = "查询代储库正常使用的货位数据信息")
  196. @ApiImplicitParams({
  197. @ApiImplicitParam(name="orgId", value="当前单位ID", paramType="query"),
  198. @ApiImplicitParam(name="stateType", value="路径状态", paramType="query")
  199. })
  200. public String selectAgentHouseWareList(Integer orgId,String stateType) throws Exception {
  201. Map<String, Object> paramMap = new HashMap<String, Object>();
  202. paramMap.put("orgId", orgId);
  203. List<Map<String, Object>> list = bgmxzService.selectAgentHouseWareList(paramMap);
  204. String str = JSON.toJSONString(list);
  205. String url = "";
  206. if(ParameterUtil.isequal(stateType,"kcsw")){
  207. url = "http://localhost:9026/agile/kcsw/queryKcswData";//库存实物
  208. }else if(ParameterUtil.isequal(stateType,"fcbgz")){
  209. url = "http://localhost:9026/agile/fcbgzController/queryFcbgzData";//分仓保管账
  210. }
  211. Map<String, Object> dataMap = new HashMap<String, Object>();
  212. dataMap.put("datas",str);
  213. String strResult = HTTPUtils.doPost(url,dataMap);
  214. return strResult;
  215. }
  216. @RequestMapping(value="/addCrkFcbgzData", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
  217. @ApiOperation(value="把出入库拿来的分仓保管账数据插入到代储库业务的分仓保管账表 中", notes = "把出入库拿来的分仓保管账数据插入到代储库业务的分仓保管账表 中")
  218. @ApiImplicitParams({
  219. @ApiImplicitParam(name="fcbgzData", value="出入库分仓保管账数据", paramType="form"),
  220. @ApiImplicitParam(name="orgId", value="当前单位ID", paramType="form"),
  221. @ApiImplicitParam(name="realName", value="当前操作人", paramType="form")
  222. })
  223. public Map<String, Object> addCrkFcbgzData(String fcbgzData, Integer orgId, String realName) {
  224. Map<String, Object> map = new HashMap<String, Object>();
  225. try {
  226. JSONArray json = JSONArray.fromObject(fcbgzData);
  227. if (json.size() > 0) {
  228. BusinessAgentBgmxz bgmxz = null;
  229. for (int i = 0; i < json.size(); i++) {
  230. bgmxz = new BusinessAgentBgmxz();
  231. JSONObject job = json.getJSONObject(i);
  232. bgmxz.setOrgId(orgId);
  233. Integer dckId = Integer.parseInt(job.get("unitid")+"");
  234. BusinessAgentDepot businessAgentDepot = bgmxzService.selectAgentDepotObj(orgId, dckId);
  235. bgmxz.setAgentId(Integer.parseInt(businessAgentDepot.getAgentId()));
  236. bgmxz.setSzlkOrgId(businessAgentDepot.getId());
  237. bgmxz.setHouseId(Integer.parseInt(job.get("ch")+""));
  238. bgmxz.setWareId(Integer.parseInt(job.get("hwh")+""));
  239. if(ParameterUtil.isnotnull(job.get("mxpz")))bgmxz.setLspz(Integer.parseInt(job.get("mxpz")+""));
  240. bgmxz.setLsxz(Integer.parseInt(job.get("hwxz")+""));
  241. bgmxz.setLsdj(Integer.parseInt(job.get("dj")+""));
  242. Date fssj = ParameterUtil.string2datetime(job.get("olddataid") + "");
  243. bgmxz.setFssj(fssj);
  244. BigDecimal number = new BigDecimal(job.get("srsl")+"");
  245. bgmxz.setSrsl(number);
  246. number = new BigDecimal(job.get("zcsl")+"");
  247. bgmxz.setZcsl(number);
  248. number = new BigDecimal(job.get("kcsl")+"");
  249. bgmxz.setKcsl(number);
  250. bgmxz.setIsJz(1);
  251. bgmxz.setSjly(1);
  252. bgmxz.setCreatePerson(realName);
  253. bgmxz.setCreateDate(fssj);
  254. //插入代储点的保管明细账表
  255. bgmxzService.insert(bgmxz);
  256. }
  257. //修改代储点货位表的保管明细账最后同步时间
  258. bgmxzService.updateAgentDepot(orgId);
  259. }
  260. map.put("status", "200");
  261. map.put("msg", "操作成功!");
  262. } catch (NumberFormatException e) {
  263. map.put("msg", "操作失败!");
  264. e.printStackTrace();
  265. }
  266. return map;
  267. }
  268. }