Parcourir la source

2021/6/18 转栏管理

yinhao il y a 4 ans
Parent
commit
a1fd05a0bc

+ 0 - 2
huimv-smart-common/src/main/java/com/huimv/common/autoconfigure/MybatisPlusConfiguration.java

@@ -1,12 +1,10 @@
 package com.huimv.common.autoconfigure;
 
 import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-
 /**
  * @Author yinhao
  * @Date 2021/4/27 9:01

+ 2 - 1
huimv-smart-gateway/src/main/java/com/huimv/gateway/HuimvSmartGatewayApplication.java

@@ -2,6 +2,7 @@ package com.huimv.gateway;
 
 import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
 import com.huimv.common.autoconfigure.ExceptionAutoConfiguration;
+import com.huimv.common.autoconfigure.MybatisPlusConfiguration;
 import com.huimv.common.knife4j.Knife4jConfiguration;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -11,7 +12,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  * @author huimv
  * @since 2021/4/29
  */
-@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class, ExceptionAutoConfiguration.class, Knife4jConfiguration.class})
+@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MybatisPlusConfiguration.class, DruidDataSourceAutoConfigure.class, ExceptionAutoConfiguration.class, Knife4jConfiguration.class})
 public class HuimvSmartGatewayApplication {
 
     public static void main(String[] args) {

+ 6 - 1
huimv-smart-management/src/main/java/com/huimv/management/dao/TransferPeriodLogDao.java

@@ -3,6 +3,9 @@ package com.huimv.management.dao;
 import com.huimv.management.entity.TransferPeriodLogEntity;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
 
 /**
  * 转栏记录表
@@ -12,6 +15,8 @@ import org.apache.ibatis.annotations.Mapper;
  * @date 2021-06-18 18:18:52
  */
 @Mapper
+@Repository
 public interface TransferPeriodLogDao extends BaseMapper<TransferPeriodLogEntity> {
-	
+
+    void batchInsert(List<TransferPeriodLogEntity> logEntityList);
 }

+ 6 - 2
huimv-smart-management/src/main/java/com/huimv/management/entity/PeriodEntity.java

@@ -28,13 +28,17 @@ public class PeriodEntity implements Serializable {
      */
     private String number;
     /**
+     * 牧场id
+     */
+    private Integer farmId;
+    /**
      * 猪舍id
      */
     private Integer pigstyId;
     /**
-     * 牧场id
+     * 单元id
      */
-    private Integer farmId;
+    private Integer unitId;
     /**
      * 删除状态 0.正常 1.已删除
      */

+ 4 - 0
huimv-smart-management/src/main/java/com/huimv/management/entity/TransferPeriodLogEntity.java

@@ -1,5 +1,7 @@
 package com.huimv.management.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 
@@ -47,10 +49,12 @@ public class TransferPeriodLogEntity implements Serializable {
 	/**
 	 * 创建时间
 	 */
+	@TableField(fill = FieldFill.INSERT)
 	private Date gmtCreate;
 	/**
 	 * 修改时间
 	 */
+	@TableField(fill = FieldFill.INSERT_UPDATE)
 	private Date gmtModified;
 	/**
 	 * 操作人

+ 79 - 52
huimv-smart-management/src/main/java/com/huimv/management/service/impl/YearPigBaseServiceImpl.java

@@ -1,14 +1,19 @@
 package com.huimv.management.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.huimv.common.exception.RRException;
 import com.huimv.common.utils.R;
 import com.huimv.management.dao.PeriodDao;
+import com.huimv.management.dao.TransferPeriodLogDao;
 import com.huimv.management.dao.UnitDao;
+import com.huimv.management.entity.PeriodEntity;
 import com.huimv.management.entity.SysUserEntity;
+import com.huimv.management.entity.TransferPeriodLogEntity;
 import com.huimv.management.entity.YearPigBaseEntity;
 import com.huimv.management.entity.vo.CountOut;
 import com.huimv.management.entity.vo.DrinkingWaterVo;
@@ -24,9 +29,11 @@ import org.springframework.stereotype.Service;
 import org.apache.commons.beanutils.BeanUtils;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.huimv.common.utils.PageUtils;
@@ -78,60 +85,59 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
         //耳标
         String eartag = (String) params.get("eartag");
         if (StringUtils.isNotEmpty(eartag)) {
-            queryWrapper.like("base.eartag",eartag);
+            queryWrapper.like("base.eartag", eartag);
         }
 
         //性别
         String sex = (String) params.get("sex");
         if (StringUtils.isNotEmpty(sex)) {
-            queryWrapper.eq("base.sex",sex);
+            queryWrapper.eq("base.sex", sex);
         }
 
         //品种
         String breed = (String) params.get("breed");
         if (StringUtils.isNotEmpty(breed)) {
-            queryWrapper.eq("base.breed",breed);
+            queryWrapper.eq("base.breed", breed);
         }
 
         //健康状态
         String healthStatus = (String) params.get("healthStatus");
         if (StringUtils.isNotEmpty(healthStatus)) {
-            queryWrapper.eq("base.health_status",Integer.parseInt(healthStatus));
+            queryWrapper.eq("base.health_status", Integer.parseInt(healthStatus));
         }
 
         //养殖状态
         String outFenceStatus = (String) params.get("outFenceStatus");
         if (StringUtils.isNotEmpty(outFenceStatus)) {
-            queryWrapper.eq("base.out_fence_status",Integer.parseInt(outFenceStatus));
+            queryWrapper.eq("base.out_fence_status", Integer.parseInt(outFenceStatus));
         }
 
         //栏期
         String periodId = (String) params.get("periodId");
         if (StringUtils.isNotEmpty(periodId)) {
-            queryWrapper.eq("base.period_id",Integer.parseInt(periodId));
+            queryWrapper.eq("base.period_id", Integer.parseInt(periodId));
         }
 
         //栋舍
         String pigstyId = (String) params.get("pigstyId");
         if (StringUtils.isNotEmpty(pigstyId)) {
-            queryWrapper.eq("base.pigsty_id",Integer.parseInt(pigstyId));
+            queryWrapper.eq("base.pigsty_id", Integer.parseInt(pigstyId));
         }
         //单元
         String unitId = (String) params.get("unitId");
         if (StringUtils.isNotEmpty(unitId)) {
-            queryWrapper.eq("base.unit_id",Integer.parseInt(unitId));
+            queryWrapper.eq("base.unit_id", Integer.parseInt(unitId));
         }
 
         //牧场
         String farmId = (String) params.get("formFarmId");
         if (StringUtils.isNotEmpty(farmId)) {
-            queryWrapper.eq("base.farm_id",Integer.parseInt(farmId));
+            queryWrapper.eq("base.farm_id", Integer.parseInt(farmId));
         }
         //排除逻辑删除
         queryWrapper.apply(" base.deleted = 0  AND pigsty.deleted = 0 AND period.deleted = 0");
 
-        IPage<PigBaseVo> page = pigBaseDao.list(new Query<>().getPage(params),queryWrapper);
-
+        IPage<PigBaseVo> page = pigBaseDao.list(new Query<>().getPage(params), queryWrapper);
 
 
         return new PageUtils(page);
@@ -139,10 +145,10 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
 
 
     @Override
-    public void batchLairage(String[] eartags,Integer periodId) {
+    public void batchLairage(String[] eartags, Integer periodId) {
         for (String eartag : eartags) {
             UpdateWrapper<YearPigBaseEntity> updateWrapper = new UpdateWrapper<YearPigBaseEntity>();
-            updateWrapper.eq("eartag",eartag).set("period_id",periodId);
+            updateWrapper.eq("eartag", eartag).set("period_id", periodId);
             update(updateWrapper);
         }
     }
@@ -155,61 +161,60 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
     @Override
     public Integer findByoutFenceStatus(int i, Integer farmId) {
         LambdaQueryWrapper<YearPigBaseEntity> wrapper = Wrappers.lambdaQuery();
-        wrapper.eq(YearPigBaseEntity::getFarmId,farmId);
-        wrapper.eq(YearPigBaseEntity::getOutFenceStatus,i);
+        wrapper.eq(YearPigBaseEntity::getFarmId, farmId);
+        wrapper.eq(YearPigBaseEntity::getOutFenceStatus, i);
         Integer integer = pigBaseDao.selectCount(wrapper);
         return integer;
     }
 
 
     @Override
-    public   Map<String ,Object> queryPageByRelationship(Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
+    public Map<String, Object> queryPageByRelationship(Map<String, Object> params) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
 
         Map<String, Object> result = new HashMap<>();
         String eartag_no = (String) params.get("eartag");
         System.out.println(eartag_no);
-        YearPigBaseEntity  self = baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, eartag_no));
+        YearPigBaseEntity self = baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, eartag_no));
         System.out.println(self);
         // result.put("self",   self  );
 
-        System.out.println("父亲ID"+self.getFatherEartag());   System.out.println("母亲ID"+self.getMotherEartag());
+        System.out.println("父亲ID" + self.getFatherEartag());
+        System.out.println("母亲ID" + self.getMotherEartag());
         String math = self.getMotherEartag();
 
-        YearPigBaseEntity father = self.getFatherEartag() == null ? null :  baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, self.getFatherEartag()));
-        YearPigBaseEntity mother = self.getMotherEartag() == null ? null :  baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, math));
+        YearPigBaseEntity father = self.getFatherEartag() == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, self.getFatherEartag()));
+        YearPigBaseEntity mother = self.getMotherEartag() == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, math));
 
 
         //父亲父母
         // result.put("father", father);
         // result.put("mother", mother);
-        YearPigBaseEntity fathermother = father == null ? null :  baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getFatherEartag()));
-        YearPigBaseEntity fatherfather = father == null ? null :  baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getMotherEartag()));
+        YearPigBaseEntity fathermother = father == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getFatherEartag()));
+        YearPigBaseEntity fatherfather = father == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, father.getMotherEartag()));
         //  result.put("fathermother", fathermother);
         // result.put("fatherfather", fatherfather);
         //母亲父母
-        YearPigBaseEntity mothermother = mother == null ? null :  baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getFatherEartag()));
-        YearPigBaseEntity  motherfather = mother == null ? null :  baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getMotherEartag()));
+        YearPigBaseEntity mothermother = mother == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getFatherEartag()));
+        YearPigBaseEntity motherfather = mother == null ? null : baseMapper.selectOne(Wrappers.<YearPigBaseEntity>lambdaQuery().eq(YearPigBaseEntity::getEartag, mother.getMotherEartag()));
         //  result.put("mothermother", mothermother);
         // result.put("motherfather", motherfather);
 
 
-
-
         Object[] intArr = new Object[7];
         Map<String, String> selfmap = BeanUtils.describe(self);
-        selfmap.put("name","self");
+        selfmap.put("name", "self");
         Map<String, String> fathermap = BeanUtils.describe(father);
-        fathermap.put("name","father");
+        fathermap.put("name", "father");
         Map<String, String> mothermap = BeanUtils.describe(mother);
-        mothermap.put("name","mother");
+        mothermap.put("name", "mother");
         Map<String, String> fathermothermap = BeanUtils.describe(fathermother);
-        fathermothermap.put("name","fathermother");
+        fathermothermap.put("name", "fathermother");
         Map<String, String> fatherfatherself = BeanUtils.describe(fatherfather);
-        fatherfatherself.put("name","fatherfather");
+        fatherfatherself.put("name", "fatherfather");
         Map<String, String> mothermotherself = BeanUtils.describe(mothermother);
-        mothermotherself.put("name","mothermother");
+        mothermotherself.put("name", "mothermother");
         Map<String, String> motherfatherself = BeanUtils.describe(motherfather);
-        motherfatherself.put("name","motherfather");
+        motherfatherself.put("name", "motherfather");
 
 
         intArr[0] = selfmap;
@@ -220,8 +225,8 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
         intArr[5] = mothermotherself;
         intArr[6] = motherfatherself;
 
-        result.put("value",intArr);
-        return   result;
+        result.put("value", intArr);
+        return result;
     }
 
     @Override
@@ -239,7 +244,7 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
         }
         wrapper.apply("deleted = 0 AND out_fence_status = 1 ");
 
-        List<CountOut> endList  = pigBaseDao.suchStatistics(farmId,wrapper);
+        List<CountOut> endList = pigBaseDao.suchStatistics(farmId, wrapper);
         System.out.println(endList);
     }
 
@@ -255,6 +260,9 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
     @Autowired
     private UnitDao unitDao;
 
+    @Autowired
+    private TransferPeriodLogDao transferPeriodLogDao;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void transferPeriod(HashMap<String, Object> map, HttpServletRequest request) {
@@ -262,37 +270,56 @@ public class YearPigBaseServiceImpl extends ServiceImpl<YearPigBaseDao, YearPigB
         String token = request.getHeader("token");
 
         HttpHeaders headers = new HttpHeaders();
-        headers.add("token",token);
-        HttpEntity httpEntity = new HttpEntity<>(null,headers);
+        headers.add("token", token);
+        HttpEntity httpEntity = new HttpEntity<>(null, headers);
 
-        ResponseEntity<R> responseEntity = restTemplate.exchange(url, HttpMethod.GET,httpEntity, R.class);
+        ResponseEntity<R> responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, R.class);
         R sysUserEntity = responseEntity.getBody();
+        if (401 == (Integer) (sysUserEntity.get("code"))) {
+            throw new RRException((String) sysUserEntity.get("msg"), (Integer) sysUserEntity.get("code"));
+        }
         String jsonString = JSONObject.toJSONString(sysUserEntity.get("user"));
-        SysUserEntity user = JSONObject.parseObject(jsonString,SysUserEntity.class);
+        SysUserEntity user = JSONObject.parseObject(jsonString, SysUserEntity.class);
 
         String username = user.getUsername();
         System.out.println(username);
 
-        List<String> earTagList = (List<String>) map.get("earTagList");
+        List<Integer> pigIds = (List<Integer>) map.get("pigIds");
         Integer periodId = (Integer) map.get("periodId");
-        System.out.println(earTagList);
-        System.out.println(periodId);
-        LambdaQueryWrapper<YearPigBaseEntity> queryWrapper = Wrappers.lambdaQuery();
-        UpdateWrapper updateWrapper = new UpdateWrapper();
-        for (String earTag : earTagList) {
 
-            queryWrapper.eq(YearPigBaseEntity::getEartag,earTag);
-            YearPigBaseEntity oldEntity = baseMapper.selectOne(queryWrapper);
-            queryWrapper.clear();
+        if (CollUtil.isEmpty(pigIds) || periodId == null) {
+            throw new RRException("参数有误,请检查!",1001);
+        }
+
+        List<TransferPeriodLogEntity> logEntityList = new ArrayList<>();
+        YearPigBaseEntity yearPigBaseEntity = new YearPigBaseEntity();
+
+        for (Integer pigId : pigIds) {
+            YearPigBaseEntity oldEntity = baseMapper.selectById(pigId);
 
             Integer oldPeriodId = oldEntity.getPeriodId();
-            String oldPeroidName = periodDao.selectById(oldPeriodId).getNumber();
+            String oldPeriodName = periodDao.selectById(oldPeriodId).getNumber();
             Integer oldUnitId = oldEntity.getUnitId();
             String oldUnitName = unitDao.selectById(oldUnitId).getNumber();
 
+            PeriodEntity newEntity = periodDao.selectById(periodId);
+            Integer newUnitId = newEntity.getUnitId();
+            String newUnitName = unitDao.selectById(newUnitId).getNumber();
+
+            TransferPeriodLogEntity entity = new TransferPeriodLogEntity();
+            entity.setEarTag(oldEntity.getEartag());
+            entity.setOldPeriod(oldPeriodName);
+            entity.setOldUnit(oldUnitName);
+            entity.setNewPeriod(newEntity.getNumber());
+            entity.setNewUnit(newUnitName);
+            entity.setOperatorUsername(username);
+            logEntityList.add(entity);
 
-//            update()
-        }
 
+            yearPigBaseEntity.setId(pigId);
+            yearPigBaseEntity.setPeriodId(periodId);
+            updateById(yearPigBaseEntity);
+        }
+        transferPeriodLogDao.batchInsert(logEntityList);
     }
 }

+ 2 - 1
huimv-smart-management/src/main/resources/mapper/management/PeriodDao.xml

@@ -7,8 +7,9 @@
     <resultMap type="com.huimv.management.entity.PeriodEntity" id="periodMap">
         <result property="id" column="id"/>
         <result property="number" column="number"/>
-        <result property="pigstyId" column="pigsty_id"/>
         <result property="farmId" column="farm_id"/>
+        <result property="pigstyId" column="pigsty_id"/>
+        <result property="unitId" column="uint_id" />
         <result property="deleted" column="deleted"/>
         <result property="gmtCreate" column="gmt_create"/>
         <result property="gmtModified" column="gmt_modified"/>

+ 16 - 0
huimv-smart-management/src/main/resources/mapper/management/TransferPeriodLogDao.xml

@@ -16,5 +16,21 @@
         <result property="operatorUsername" column="operator_username"/>
     </resultMap>
 
+    <insert id="batchInsert">
+        INSERT INTO mgt_transfer_period_log(ear_tag, old_period, new_period, old_unit, new_unit, gmt_create, gmt_modified, operator_username) VALUES
+        <foreach collection="list" item="item" separator=",">
+            (
+            #{item.earTag},
+            #{item.oldPeriod},
+            #{item.newPeriod},
+            #{item.oldUnit},
+            #{item.newUnit},
+            now(),
+            now(),
+            #{item.operatorUsername}
+            )
+        </foreach>
+    </insert>
+
 
 </mapper>