YearPigBaseController.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package com.huimv.management.controller;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.text.NumberFormat;
  4. import java.util.*;
  5. import com.huimv.management.entity.UnitEntity;
  6. import com.huimv.management.entity.vo.CountOut;
  7. import com.huimv.management.service.UnitService;
  8. import io.swagger.annotations.Api;
  9. import org.apache.commons.lang.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import com.huimv.management.entity.YearPigBaseEntity;
  13. import com.huimv.management.service.YearPigBaseService;
  14. import com.huimv.common.utils.PageUtils;
  15. import com.huimv.common.utils.R;
  16. import javax.servlet.http.HttpServletRequest;
  17. /**
  18. * 年猪基本
  19. *
  20. * @author yinhao
  21. * @email yinhao@163.com
  22. * @date 2021-05-07 15:32:42
  23. */
  24. @Api(tags = "年猪基本")
  25. @RestController
  26. @RequestMapping("management/yearpigbase")
  27. public class YearPigBaseController {
  28. @Autowired
  29. private YearPigBaseService yearPigBaseService;
  30. @Autowired
  31. private UnitService unitService;
  32. /**
  33. * 列表
  34. */
  35. @RequestMapping("/list")
  36. public R list(@RequestParam Map<String, Object> params){
  37. PageUtils page = yearPigBaseService.queryPage(params);
  38. return R.ok().put("page", page);
  39. }
  40. /**
  41. * 列表
  42. */
  43. @RequestMapping("/fattenList")
  44. public R fattenList(@RequestParam Map<String, Object> params){
  45. PageUtils page = yearPigBaseService.fattenList(params);
  46. return R.ok().put("page", page);
  47. }
  48. /**
  49. * 信息
  50. */
  51. @RequestMapping("/info/{id}")
  52. public R info(@PathVariable("id") Integer id){
  53. YearPigBaseEntity yearPigBase = yearPigBaseService.getById(id);
  54. return R.ok().put("yearPigBase", yearPigBase);
  55. }
  56. /**
  57. * 保存
  58. */
  59. @RequestMapping("/save")
  60. public R save(@RequestBody YearPigBaseEntity yearPigBase){
  61. yearPigBaseService.save(yearPigBase);
  62. return R.ok();
  63. }
  64. /**
  65. * 修改
  66. */
  67. @RequestMapping("/update")
  68. public R update(@RequestBody YearPigBaseEntity yearPigBase){
  69. Integer unitId = yearPigBase.getUnitId();
  70. if (unitId == null){
  71. return R.error("请选择单元");
  72. }
  73. Integer currentPeriodId = unitService.getById(unitId).getCurrentPeriodId();
  74. if (currentPeriodId == null){
  75. return R.error("该单元暂无栏期");
  76. }
  77. yearPigBase.setPeriodId(currentPeriodId);
  78. yearPigBaseService.updateById(yearPigBase);
  79. return R.ok();
  80. }
  81. /**
  82. * 删除
  83. */
  84. @RequestMapping("/delete")
  85. public R delete(@RequestBody Integer[] ids){
  86. yearPigBaseService.removeByIds(Arrays.asList(ids));
  87. return R.ok();
  88. }
  89. /*@RequestMapping("/batchLairage")
  90. public R batchLairage(@RequestBody Map<String, Object> map){
  91. String eartags = (String)map.get("eartags");
  92. Integer periodId = (Integer)map.get("periodId");
  93. String[] split = eartags.split(",");
  94. yearPigBaseService.batchLairage(split,periodId);
  95. return R.ok();
  96. } */
  97. //批量入栏
  98. @RequestMapping("/batchLairage")
  99. public R batchLairage(@RequestBody YearPigBaseEntity yearPigBase){
  100. Integer unitId = yearPigBase.getUnitId();
  101. UnitEntity unitEntity = unitService.getById(unitId);
  102. if (unitEntity != null){
  103. yearPigBase.setPeriodId(unitEntity.getCurrentPeriodId());
  104. }
  105. for (String eartage : yearPigBase.getEartag().split(",")) {
  106. yearPigBase.setEartag(eartage);
  107. yearPigBaseService.save(yearPigBase);
  108. }
  109. return R.ok();
  110. }
  111. //批量出栏
  112. @RequestMapping("/such")
  113. public R such(@RequestBody Integer[] ids){
  114. // YearPigBaseEntity yearPigBaseEntity = new YearPigBaseEntity();
  115. // yearPigBaseEntity.setOutFenceStatus(1);
  116. // yearPigBaseEntity.setOutFenceTime(new Date());
  117. //
  118. //
  119. // for (Integer id : ids) {
  120. // yearPigBaseEntity.setId(id);
  121. // yearPigBaseService.updateById(yearPigBaseEntity);
  122. // }
  123. yearPigBaseService.such(ids);
  124. return R.ok();
  125. }
  126. //批量出栏
  127. @RequestMapping("/suchApp")
  128. public R suchApp(String[] ids){
  129. yearPigBaseService.suchApp(ids);
  130. return R.ok();
  131. }
  132. //认养未认养比例
  133. @RequestMapping("/outAndInProportion")
  134. public R outAndInProportion(Integer formFarmId){
  135. //以认养
  136. Integer adopted = yearPigBaseService.findByFosterStatus(1,formFarmId);
  137. //未认养
  138. Integer notAdopted = yearPigBaseService.findByFosterStatus(0,formFarmId);
  139. Map resultMap = new HashMap();
  140. resultMap.put("adopted",adopted);
  141. resultMap.put("notAdopted",notAdopted);
  142. Integer total = notAdopted + adopted;
  143. resultMap.put("total",total);
  144. NumberFormat numberFormat = NumberFormat.getInstance();
  145. numberFormat.setMaximumFractionDigits(2);
  146. String adoptedPercent =numberFormat.format((float)adopted/(float)total*100);
  147. String notAdoptedPercent =numberFormat.format((float)notAdopted/(float)total*100);
  148. resultMap.put("adoptedPercent",adoptedPercent+"%");
  149. resultMap.put("notAdoptedPercent",notAdoptedPercent+"%");
  150. return R.ok().put("data",resultMap);
  151. }
  152. /**
  153. * 查谱系问题,请求头中需要有ID
  154. */
  155. @RequestMapping("/queryByRelationship")
  156. public R queryPageByRelationship(@RequestParam Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
  157. Map<String, Object> stringObjectMap = yearPigBaseService.queryPageByRelationship(params);
  158. return R.ok().put("Result", stringObjectMap);
  159. }
  160. /*
  161. * 出栏统计,每天
  162. */
  163. @RequestMapping("/suchStatisticsDay")
  164. public R suchStatistics(@RequestParam Map<String, Object> params){
  165. String startTime = (String)params.get("startTime");
  166. String endTime = (String)params.get("endTime");
  167. String farmId = (String)params.get("formFarmId");
  168. if (StringUtils.isBlank(farmId)) {
  169. return R.error("牧场信息为空");
  170. }
  171. List<CountOut> countOuts = yearPigBaseService.suchStatistics(startTime, endTime, Integer.parseInt(farmId));
  172. return R.ok().put("data",countOuts);
  173. }
  174. /*
  175. * 出栏统计,每月
  176. */
  177. @RequestMapping("/suchStatisticsMonth")
  178. public R suchStatisticsMonth(@RequestParam Map<String, Object> params){
  179. String startTime = (String)params.get("startTime");
  180. String endTime = (String)params.get("endTime");
  181. String farmId = (String)params.get("formFarmId");
  182. if (StringUtils.isBlank(farmId)) {
  183. return R.error("牧场信息为空");
  184. }
  185. List<CountOut> countOuts = yearPigBaseService.suchStatisteicsMonth(startTime, endTime, Integer.parseInt(farmId));
  186. return R.ok().put("data",countOuts);
  187. }
  188. @PostMapping("/transferPeriod")
  189. public R transferPeriod(@RequestBody HashMap<String,Object> map, HttpServletRequest request) {
  190. yearPigBaseService.transferPeriod(map,request);
  191. return R.ok();
  192. }
  193. }