YearPigBaseController.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. for (String eartage : yearPigBase.getEartag().split(",")) {
  79. yearPigBase.setEartag(eartage);
  80. yearPigBaseService.updateById(yearPigBase);
  81. }
  82. return R.ok();
  83. }
  84. /**
  85. * 删除
  86. */
  87. @RequestMapping("/delete")
  88. public R delete(@RequestBody Integer[] ids){
  89. yearPigBaseService.removeByIds(Arrays.asList(ids));
  90. return R.ok();
  91. }
  92. /*@RequestMapping("/batchLairage")
  93. public R batchLairage(@RequestBody Map<String, Object> map){
  94. String eartags = (String)map.get("eartags");
  95. Integer periodId = (Integer)map.get("periodId");
  96. String[] split = eartags.split(",");
  97. yearPigBaseService.batchLairage(split,periodId);
  98. return R.ok();
  99. } */
  100. //批量入栏
  101. @RequestMapping("/batchLairage")
  102. public R batchLairage(@RequestBody YearPigBaseEntity yearPigBase){
  103. Integer unitId = yearPigBase.getUnitId();
  104. UnitEntity unitEntity = unitService.getById(unitId);
  105. if (unitEntity != null){
  106. yearPigBase.setPeriodId(unitEntity.getCurrentPeriodId());
  107. }
  108. for (String eartage : yearPigBase.getEartag().split(",")) {
  109. yearPigBase.setEartag(eartage);
  110. yearPigBaseService.save(yearPigBase);
  111. }
  112. return R.ok();
  113. }
  114. //批量出栏
  115. @RequestMapping("/such")
  116. public R such(@RequestBody Integer[] ids){
  117. // YearPigBaseEntity yearPigBaseEntity = new YearPigBaseEntity();
  118. // yearPigBaseEntity.setOutFenceStatus(1);
  119. // yearPigBaseEntity.setOutFenceTime(new Date());
  120. //
  121. //
  122. // for (Integer id : ids) {
  123. // yearPigBaseEntity.setId(id);
  124. // yearPigBaseService.updateById(yearPigBaseEntity);
  125. // }
  126. yearPigBaseService.such(ids);
  127. return R.ok();
  128. }
  129. //批量出栏
  130. @RequestMapping("/suchApp")
  131. public R suchApp(String[] ids){
  132. yearPigBaseService.suchApp(ids);
  133. return R.ok();
  134. }
  135. //认养未认养比例
  136. @RequestMapping("/outAndInProportion")
  137. public R outAndInProportion(Integer formFarmId){
  138. //以认养
  139. Integer adopted = yearPigBaseService.findByFosterStatus(1,formFarmId);
  140. //未认养
  141. Integer notAdopted = yearPigBaseService.findByFosterStatus(0,formFarmId);
  142. Map resultMap = new HashMap();
  143. resultMap.put("adopted",adopted);
  144. resultMap.put("notAdopted",notAdopted);
  145. Integer total = notAdopted + adopted;
  146. resultMap.put("total",total);
  147. NumberFormat numberFormat = NumberFormat.getInstance();
  148. numberFormat.setMaximumFractionDigits(2);
  149. String adoptedPercent =numberFormat.format((float)adopted/(float)total*100);
  150. String notAdoptedPercent =numberFormat.format((float)notAdopted/(float)total*100);
  151. resultMap.put("adoptedPercent",adoptedPercent+"%");
  152. resultMap.put("notAdoptedPercent",notAdoptedPercent+"%");
  153. return R.ok().put("data",resultMap);
  154. }
  155. /**
  156. * 查谱系问题,请求头中需要有ID
  157. */
  158. @RequestMapping("/queryByRelationship")
  159. public R queryPageByRelationship(@RequestParam Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
  160. Map<String, Object> stringObjectMap = yearPigBaseService.queryPageByRelationship(params);
  161. return R.ok().put("Result", stringObjectMap);
  162. }
  163. /*
  164. * 出栏统计,每天
  165. */
  166. @RequestMapping("/suchStatisticsDay")
  167. public R suchStatistics(@RequestParam Map<String, Object> params){
  168. String startTime = (String)params.get("startTime");
  169. String endTime = (String)params.get("endTime");
  170. String farmId = (String)params.get("formFarmId");
  171. if (StringUtils.isBlank(farmId)) {
  172. return R.error("牧场信息为空");
  173. }
  174. List<CountOut> countOuts = yearPigBaseService.suchStatistics(startTime, endTime, Integer.parseInt(farmId));
  175. return R.ok().put("data",countOuts);
  176. }
  177. /*
  178. * 出栏统计,每月
  179. */
  180. @RequestMapping("/suchStatisticsMonth")
  181. public R suchStatisticsMonth(@RequestParam Map<String, Object> params){
  182. String startTime = (String)params.get("startTime");
  183. String endTime = (String)params.get("endTime");
  184. String farmId = (String)params.get("formFarmId");
  185. if (StringUtils.isBlank(farmId)) {
  186. return R.error("牧场信息为空");
  187. }
  188. List<CountOut> countOuts = yearPigBaseService.suchStatisteicsMonth(startTime, endTime, Integer.parseInt(farmId));
  189. return R.ok().put("data",countOuts);
  190. }
  191. /**
  192. * 转栏
  193. * @param map
  194. * @param request
  195. * @return
  196. */
  197. @PostMapping("/transferPeriod")
  198. public R transferPeriod(@RequestBody HashMap<String,Object> map, HttpServletRequest request) {
  199. yearPigBaseService.transferPeriod(map,request);
  200. return R.ok();
  201. }
  202. /**
  203. * 转栏
  204. * @param map
  205. * @param request
  206. * @return
  207. */
  208. @PostMapping("/transferPeriodClient")
  209. public R transferPeriodClient(@RequestBody HashMap<String,Object> map, HttpServletRequest request) {
  210. yearPigBaseService.transferPeriodClient(map,request);
  211. return R.ok();
  212. }
  213. //查询认养,未认养,出栏,育肥
  214. @RequestMapping("/statisticsAll")
  215. public R statisticsAll(@RequestParam Map<String, Object> params){
  216. String formFarmId = (String) params.get("formFarmId");
  217. if (formFarmId == null || "".equals(formFarmId) ){
  218. return R.error("请选择牧场");
  219. }
  220. HashMap<String,Integer> resultMap = yearPigBaseService.statisticsAll(params);
  221. return R.ok().put("data",resultMap);
  222. }
  223. }