package com.chinaitop.depot.agent.bgz.controller; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgzz; import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgzzExample; import com.chinaitop.depot.agent.bgz.model.BusinessAgentBgzzExample.Criteria; import com.chinaitop.depot.agent.bgz.service.BusinessAgentBgzzService; import com.chinaitop.utils.ParameterUtil; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; @RestController @RequestMapping(value = "/agent_bgzz") @Api(description = "代储库保管总账控制类") public class BusinessAgentBgzzController { @Resource private BusinessAgentBgzzService bgzzService; @RequestMapping(value = "/getList", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) @ApiOperation(value="代储库分仓保管账信息列表", notes = "代储库分仓保管账信息列表") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query"), @ApiImplicitParam(name = "bgzzJson", value = "条件对象", paramType = "query") }) public PageInfo list(Integer pageNum, Integer pageSize, String bgzzJson) { ObjectMapper mapper = new ObjectMapper(); BusinessAgentBgzz bgzz = null; try { bgzz = (BusinessAgentBgzz) mapper.readValue(bgzzJson, BusinessAgentBgzz.class); } catch (Exception e) { e.printStackTrace(); } BusinessAgentBgzzExample example = new BusinessAgentBgzzExample(); Criteria criteria = example.createCriteria(); /* orgId */ if(ParameterUtil.isnotnull(bgzz.getOrgId())){ criteria.andAgentIdEqualTo(bgzz.getOrgId()); } /* 代储点ID */ if(ParameterUtil.isnotnull(bgzz.getAgentId())){ criteria.andAgentIdEqualTo(bgzz.getAgentId()); } /* 代储库ID */ if(ParameterUtil.isnotnull(bgzz.getDckId())){ criteria.andDckIdEqualTo(bgzz.getDckId()); } /* 粮食品种ID */ if(ParameterUtil.isnotnull(bgzz.getLspz())){ criteria.andLspzEqualTo(bgzz.getLspz()); } /* 粮食性质ID */ if(ParameterUtil.isnotnull(bgzz.getLsxz())){ criteria.andLsxzEqualTo(bgzz.getLsxz()); } /* 业务月份 */ if(ParameterUtil.isnotnull(bgzz.getFssj())){ criteria.andFssjEqualTo(bgzz.getFssj()); } /* 分页 */ if(ParameterUtil.isnotnull(pageNum) && ParameterUtil.isnotnull(pageSize)){ PageHelper.startPage(pageNum, pageSize); } List list = bgzzService.findByConditions(example); PageInfo pageInfo = new PageInfo(list); return pageInfo; } @RequestMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @ApiOperation(value="新增或修改代储库保管总账信息", notes = "新增或修改代储库保管总账信息") @ApiImplicitParams({ @ApiImplicitParam(name = "bgzzJson", value = "数据对象", paramType = "form"), @ApiImplicitParam(name = "type", value = "操作类型", paramType = "form") }) public Map edit(String bgzzJson, String type) { Map modelMap = new HashMap(); // JSON字符串转对象 ObjectMapper mapper = new ObjectMapper(); try { BusinessAgentBgzz bgzz = (BusinessAgentBgzz) mapper.readValue(bgzzJson, BusinessAgentBgzz.class); if (type != null && "shenhe".equals(type)) { bgzzService.update(bgzz); } else { /** * 实现思路: * 1、查询是否记过账 * 2、如果记过账则直接修改数据就行,否则就新增记账数据 */ BusinessAgentBgzzExample example = new BusinessAgentBgzzExample(); Criteria criteria = example.createCriteria(); /* orgId */ if(ParameterUtil.isnotnull(bgzz.getOrgId())){ criteria.andOrgIdEqualTo(bgzz.getOrgId()); } /* 代储点ID */ if(ParameterUtil.isnotnull(bgzz.getAgentId())){ criteria.andAgentIdEqualTo(bgzz.getAgentId()); } /* 代储库ID */ if(ParameterUtil.isnotnull(bgzz.getDckId())){ criteria.andDckIdEqualTo(bgzz.getDckId()); } /* 粮食品种ID */ if(ParameterUtil.isnotnull(bgzz.getLspz())){ criteria.andLspzEqualTo(bgzz.getLspz()); } /* 粮食性质ID */ if(ParameterUtil.isnotnull(bgzz.getLsxz())){ criteria.andLsxzEqualTo(bgzz.getLsxz()); } /* 业务月份 */ if(ParameterUtil.isnotnull(bgzz.getFssj())){ criteria.andFssjEqualTo(bgzz.getFssj()); } List list = bgzzService.findByConditions(example); if (null != list && list.size() > 0) { bgzzService.update(bgzz); } else { bgzzService.insert(bgzz); } } modelMap.put("status", "success"); modelMap.put("msg", "操作成功!"); } catch (Exception e) { e.printStackTrace(); modelMap.put("status", "error"); modelMap.put("msg", "操作失败!"); } return modelMap; } }