123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- package com.huimv.management.controller;
- import java.lang.reflect.InvocationTargetException;
- import java.text.NumberFormat;
- import java.util.*;
- import com.huimv.management.entity.UnitEntity;
- import com.huimv.management.entity.vo.CountOut;
- import com.huimv.management.service.UnitService;
- import io.swagger.annotations.Api;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import com.huimv.management.entity.YearPigBaseEntity;
- import com.huimv.management.service.YearPigBaseService;
- import com.huimv.common.utils.PageUtils;
- import com.huimv.common.utils.R;
- import javax.servlet.http.HttpServletRequest;
- /**
- * 年猪基本
- *
- * @author yinhao
- * @email yinhao@163.com
- * @date 2021-05-07 15:32:42
- */
- @Api(tags = "年猪基本")
- @RestController
- @RequestMapping("management/yearpigbase")
- public class YearPigBaseController {
- @Autowired
- private YearPigBaseService yearPigBaseService;
- @Autowired
- private UnitService unitService;
- /**
- * 列表
- */
- @RequestMapping("/list")
- public R list(@RequestParam Map<String, Object> params){
- PageUtils page = yearPigBaseService.queryPage(params);
- return R.ok().put("page", page);
- }
- /**
- * 列表
- */
- @RequestMapping("/fattenList")
- public R fattenList(@RequestParam Map<String, Object> params){
- PageUtils page = yearPigBaseService.fattenList(params);
- return R.ok().put("page", page);
- }
- /**
- * 信息
- */
- @RequestMapping("/info/{id}")
- public R info(@PathVariable("id") Integer id){
- YearPigBaseEntity yearPigBase = yearPigBaseService.getById(id);
- return R.ok().put("yearPigBase", yearPigBase);
- }
- /**
- * 保存
- */
- @RequestMapping("/save")
- public R save(@RequestBody YearPigBaseEntity yearPigBase){
- yearPigBaseService.save(yearPigBase);
- return R.ok();
- }
- /**
- * 修改
- */
- @RequestMapping("/update")
- public R update(@RequestBody YearPigBaseEntity yearPigBase){
- Integer unitId = yearPigBase.getUnitId();
- if (unitId == null){
- return R.error("请选择单元");
- }
- Integer currentPeriodId = unitService.getById(unitId).getCurrentPeriodId();
- if (currentPeriodId == null){
- return R.error("该单元暂无栏期");
- }
- yearPigBase.setPeriodId(currentPeriodId);
- for (String eartage : yearPigBase.getEartag().split(",")) {
- yearPigBase.setEartag(eartage);
- yearPigBaseService.updateById(yearPigBase);
- }
- return R.ok();
- }
- /**
- * 删除
- */
- @RequestMapping("/delete")
- public R delete(@RequestBody Integer[] ids){
- yearPigBaseService.removeByIds(Arrays.asList(ids));
- return R.ok();
- }
- /*@RequestMapping("/batchLairage")
- public R batchLairage(@RequestBody Map<String, Object> map){
- String eartags = (String)map.get("eartags");
- Integer periodId = (Integer)map.get("periodId");
- String[] split = eartags.split(",");
- yearPigBaseService.batchLairage(split,periodId);
- return R.ok();
- } */
- //批量入栏
- @RequestMapping("/batchLairage")
- public R batchLairage(@RequestBody YearPigBaseEntity yearPigBase){
- Integer unitId = yearPigBase.getUnitId();
- UnitEntity unitEntity = unitService.getById(unitId);
- if (unitEntity != null){
- yearPigBase.setPeriodId(unitEntity.getCurrentPeriodId());
- }
- for (String eartage : yearPigBase.getEartag().split(",")) {
- yearPigBase.setEartag(eartage);
- yearPigBaseService.save(yearPigBase);
- }
- return R.ok();
- }
- //批量出栏
- @RequestMapping("/such")
- public R such(@RequestBody Integer[] ids){
- // YearPigBaseEntity yearPigBaseEntity = new YearPigBaseEntity();
- // yearPigBaseEntity.setOutFenceStatus(1);
- // yearPigBaseEntity.setOutFenceTime(new Date());
- //
- //
- // for (Integer id : ids) {
- // yearPigBaseEntity.setId(id);
- // yearPigBaseService.updateById(yearPigBaseEntity);
- // }
- yearPigBaseService.such(ids);
- return R.ok();
- }
- //批量出栏
- @RequestMapping("/suchApp")
- public R suchApp(String[] ids){
- yearPigBaseService.suchApp(ids);
- return R.ok();
- }
- //认养未认养比例
- @RequestMapping("/outAndInProportion")
- public R outAndInProportion(Integer formFarmId){
- //以认养
- Integer adopted = yearPigBaseService.findByFosterStatus(1,formFarmId);
- //未认养
- Integer notAdopted = yearPigBaseService.findByFosterStatus(0,formFarmId);
- Map resultMap = new HashMap();
- resultMap.put("adopted",adopted);
- resultMap.put("notAdopted",notAdopted);
- Integer total = notAdopted + adopted;
- resultMap.put("total",total);
- NumberFormat numberFormat = NumberFormat.getInstance();
- numberFormat.setMaximumFractionDigits(2);
- String adoptedPercent =numberFormat.format((float)adopted/(float)total*100);
- String notAdoptedPercent =numberFormat.format((float)notAdopted/(float)total*100);
- resultMap.put("adoptedPercent",adoptedPercent+"%");
- resultMap.put("notAdoptedPercent",notAdoptedPercent+"%");
- return R.ok().put("data",resultMap);
- }
- /**
- * 查谱系问题,请求头中需要有ID
- */
- @RequestMapping("/queryByRelationship")
- public R queryPageByRelationship(@RequestParam Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
- Map<String, Object> stringObjectMap = yearPigBaseService.queryPageByRelationship(params);
- return R.ok().put("Result", stringObjectMap);
- }
- /*
- * 出栏统计,每天
- */
- @RequestMapping("/suchStatisticsDay")
- public R suchStatistics(@RequestParam Map<String, Object> params){
- String startTime = (String)params.get("startTime");
- String endTime = (String)params.get("endTime");
- String farmId = (String)params.get("formFarmId");
- if (StringUtils.isBlank(farmId)) {
- return R.error("牧场信息为空");
- }
- List<CountOut> countOuts = yearPigBaseService.suchStatistics(startTime, endTime, Integer.parseInt(farmId));
- return R.ok().put("data",countOuts);
- }
- /*
- * 出栏统计,每月
- */
- @RequestMapping("/suchStatisticsMonth")
- public R suchStatisticsMonth(@RequestParam Map<String, Object> params){
- String startTime = (String)params.get("startTime");
- String endTime = (String)params.get("endTime");
- String farmId = (String)params.get("formFarmId");
- if (StringUtils.isBlank(farmId)) {
- return R.error("牧场信息为空");
- }
- List<CountOut> countOuts = yearPigBaseService.suchStatisteicsMonth(startTime, endTime, Integer.parseInt(farmId));
- return R.ok().put("data",countOuts);
- }
- /**
- * 转栏
- * @param map
- * @param request
- * @return
- */
- @PostMapping("/transferPeriod")
- public R transferPeriod(@RequestBody HashMap<String,Object> map, HttpServletRequest request) {
- yearPigBaseService.transferPeriod(map,request);
- return R.ok();
- }
- /**
- * 转栏
- * @param map
- * @param request
- * @return
- */
- @PostMapping("/transferPeriodClient")
- public R transferPeriodClient(@RequestBody HashMap<String,Object> map, HttpServletRequest request) {
- yearPigBaseService.transferPeriodClient(map,request);
- return R.ok();
- }
- //查询认养,未认养,出栏,育肥
- @RequestMapping("/statisticsAll")
- public R statisticsAll(@RequestParam Map<String, Object> params){
- String formFarmId = (String) params.get("formFarmId");
- if (formFarmId == null || "".equals(formFarmId) ){
- return R.error("请选择牧场");
- }
- HashMap<String,Integer> resultMap = yearPigBaseService.statisticsAll(params);
- return R.ok().put("data",resultMap);
- }
- }
|