ソースを参照

新增 生成二十四节气功能

zhaiyifei 1 年間 前
コミット
0cc8118e4b

+ 46 - 5
src/main/java/com/yunfeiyun/agmp/fms/controller/FmsSolarController.java

@@ -1,12 +1,15 @@
 package com.yunfeiyun.agmp.fms.controller;
 
 import com.yunfeiyun.agmp.common.annotation.Log;
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.controller.BaseController;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.enums.BusinessType;
+import com.yunfeiyun.agmp.common.exception.BizException;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.SecurityUtils;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
 import com.yunfeiyun.agmp.fms.domain.FmsSolar;
 import com.yunfeiyun.agmp.fms.service.IFmsSolarService;
@@ -15,8 +18,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 // TODO://该业务相关接口均弃用
 /**
  * 节气时令Controller
@@ -29,9 +33,6 @@ import java.util.List;
 @Deprecated
 public class FmsSolarController extends BaseController
 {
-
-
-
     @Autowired
     private IFmsSolarService fmsSolarService;
 
@@ -43,6 +44,27 @@ public class FmsSolarController extends BaseController
     public TableDataInfo list(FmsSolar fmsSolar) {
         startPage();
         List<FmsSolar> list = fmsSolarService.selectFmsSolarList(fmsSolar);
+        if(list.isEmpty()){
+            fmsSolarService.updateFmsSolarAll();
+            list = fmsSolarService.selectFmsSolarList(fmsSolar);
+        }else{
+            FmsSolar tidFmsSolar = new FmsSolar();
+            tidFmsSolar.setTid(SecurityUtils.getTid());
+            List<FmsSolar> userFmsSorlarlist = fmsSolarService.selectFmsSolarList(tidFmsSolar);
+
+            Map<String, FmsSolar> fmsSolarMap = new HashMap<>();
+            for(FmsSolar fms : userFmsSorlarlist){
+                String solarName = fms.getSolarName();
+                fmsSolarMap.put(solarName, fms);
+            }
+            for(int i = 0; i < list.size(); i++){
+                FmsSolar f = list.get(i);
+                String solarName = f.getSolarName();
+                if(fmsSolarMap.containsKey(solarName)){
+                    list.set(i, fmsSolarMap.get(solarName));
+                }
+            }
+        }
         return getDataTable(list);
     }
 
@@ -53,6 +75,7 @@ public class FmsSolarController extends BaseController
     @Log(title = "节气时令", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response,@RequestBody FmsSolar fmsSolar) {
+        fmsSolar.setTid(SecurityUtils.getTid());
         List<FmsSolar> list = fmsSolarService.selectFmsSolarList(fmsSolar);
         ExcelUtil<FmsSolar> util = new ExcelUtil<FmsSolar>(FmsSolar.class);
         util.exportExcel(response, list, "节气时令数据");
@@ -101,7 +124,25 @@ public class FmsSolarController extends BaseController
     @Log(title = "节气时令", businessType = BusinessType.UPDATE)
     @PutMapping("/edit")
     public AjaxResult edit(@RequestBody FmsSolar fmsSolar) {
-        return toAjax(fmsSolarService.updateFmsSolar(fmsSolar));
+        String tid = SecurityUtils.getTid();
+        String solarId = fmsSolar.getSolarId();
+
+        if(StringUtils.isEmpty(solarId)){
+            throw new BizException(ErrorCode.INVALID_PARAMETER.getCode(),"solarId不能为空");
+        }
+
+        FmsSolar oldFmsSolar = fmsSolarService.selectFmsSolarBySolarId(solarId, tid);
+
+        fmsSolar.setTid(tid);
+        int status = 0;
+        if(oldFmsSolar == null){
+            fmsSolar.setSolarId(fmsSolar.getId());
+            status = fmsSolarService.insertFmsSolar(fmsSolar);
+        }else{
+            status = fmsSolarService.updateFmsSolar(fmsSolar);
+        }
+
+        return toAjax(status);
     }
 
     /**

+ 7 - 2
src/main/java/com/yunfeiyun/agmp/fms/service/impl/FmsSolarServiceImpl.java

@@ -59,6 +59,10 @@ public class FmsSolarServiceImpl implements IFmsSolarService
      */
     @Override
     public List<FmsSolar> selectFmsSolarList(FmsSolar fmsSolar) {
+        fmsSolar.setYear(String.valueOf(LocalDate.now().getYear()));
+        if (StringUtil.isEmpty(fmsSolar.getTid())) {
+            fmsSolar.setTid("");
+        }
         return fmsSolarMapper.selectFmsSolarList(fmsSolar);
     }
 
@@ -70,6 +74,7 @@ public class FmsSolarServiceImpl implements IFmsSolarService
      */
     @Override
     public int insertFmsSolar(FmsSolar fmsSolar) {
+        fmsSolar.setYear(String.valueOf(LocalDate.now().getYear()));
         return fmsSolarMapper.insertFmsSolar(fmsSolar);
     }
 
@@ -150,7 +155,7 @@ public class FmsSolarServiceImpl implements IFmsSolarService
             int year = currentDate.getYear();
 
             FmsSolar selectFmsSolar = new FmsSolar();
-            selectFmsSolar.setTid(null);
+            selectFmsSolar.setTid("");
             selectFmsSolar.setYear(String.valueOf(year));
 
             List<FmsSolar> fmsSolarList = selectFmsSolarList(selectFmsSolar);
@@ -177,7 +182,7 @@ public class FmsSolarServiceImpl implements IFmsSolarService
                 if(!solarMap.containsKey(key)){
                     FmsSolar fmsSolar = new FmsSolar();
                     fmsSolar.setSolarId(fmsSolar.getId());
-                    fmsSolar.setTid(null);
+                    fmsSolar.setTid("");
                     fmsSolar.setYear(String.valueOf(year));
                     fmsSolar.setSolarName(solarName);
                     fmsSolar.setSolarStartdate(startDate);

+ 3 - 5
src/main/resources/mapper/FmsSolarMapper.xml

@@ -5,14 +5,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <mapper namespace="com.yunfeiyun.agmp.fms.mapper.FmsSolarMapper">
 
     <sql id="selectFmsSolarVo">
-        select solarId, solarName, solarRemark, solarStartdate, solarDigest, year
+        select solarId, solarName, solarRemark, solarStartdate, solarDigest, year, tid
         from FmsSolar
     </sql>
 
     <select id="selectFmsSolarList" parameterType="FmsSolar" resultType="FmsSolar">
         <include refid="selectFmsSolarVo"/>
         <where>
-            (tid = #{tid} or tid is #{tid})
+            tid = #{tid}
             <if test="solarName != null  and solarName != ''"> and solarName like concat('%', #{solarName}, '%')</if>
             <if test="solarRemark != null  and solarRemark != ''"> and solarRemark = #{solarRemark}</if>
             <if test="solarStartdate != null  and solarStartdate != ''"> and solarStartdate = #{solarStartdate}</if>
@@ -93,10 +93,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="solarRemark != null">solarRemark = #{solarRemark},</if>
             <if test="solarStartdate != null">solarStartdate = #{solarStartdate},</if>
             <if test="solarDigest != null">solarDigest = #{solarDigest},</if>
-            <if test="tid != null">tid = #{tid},</if>
         </trim>
-        where solarName = #{solarName} and year = #{year}
-        <if test="tid != null and tid !='' and tid != '-1'">and tid = #{tid}</if>
+        where solarId = #{solarId} and tid = #{tid}
     </update>
 
     <update id="updateFmsSolarByBatch" parameterType="FmsSolar">