Bläddra i källkod

新增部门分页查询,通过部门id分页查询栏目信息,部门表,部门栏目管理表增加逻辑删除字段

hyx 2 år sedan
förälder
incheckning
f0cd778d2d

+ 58 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/TjController.java

@@ -5,6 +5,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.example.nngkxxdp.entity.Department;
 import com.example.nngkxxdp.util.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -164,4 +165,61 @@ public class TjController {
     public void computeRecord(String date) {
         wzkpRecordUtil.generateRecord(date);
     }
+
+    /**
+     * 通过page,limit分页查询部门的信息
+     *
+     * @param page
+     * @param limit
+     * @param deptName 部门名称搜索
+     * @return
+     */
+    @GetMapping("/getDeptPage")
+    public Map<String, Object> getDeptPage(Integer page, Integer limit, String deptName) {
+        try {
+            if (Blank.isNotEmpty(page) && Blank.isNotEmpty(limit) && page > 0 && limit > 0) {
+                return SendUtil.send(true, null, tjService.getDeptPage(page, limit, deptName));
+            }
+            return SendUtil.send(true, ConstStr.REQUEST_WRONGPARAMS, "page和limit不能为空,且要大于0");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return SendUtil.send(false, ConstStr.RESULT_FAILED);
+    }
+
+    @PostMapping("/saveDept")
+    public Map<String,Object> saveDept(Department department){
+        try {
+            return tjService.saveDept(department);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return SendUtil.send(false, ConstStr.RESULT_FAILED);
+    }
+
+    @GetMapping("/getDeptById")
+    public Map<String, Object> getDeptById(Integer deptid) {
+        try {
+            if (Blank.isEmpty(deptid)) {
+                return SendUtil.send(false, "id为空");
+            }
+            return SendUtil.send(true, null, tjService.getDeptById(deptid));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return SendUtil.send(false, ConstStr.DATA_NOT_FOUND);
+    }
+
+    @GetMapping("/getChnlidListByDeptid")
+    public Map<String, Object> getChnlidListByDeptid(Integer page, Integer limit, Integer deptid) {
+        try {
+            if (Blank.isNotEmpty(deptid)) {
+                return SendUtil.send(true, null, tjService.getChnlidListByDeptid(page, limit, deptid));
+            }
+            return SendUtil.send(true, ConstStr.REQUEST_WRONGPARAMS, "deptid不能为空");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return SendUtil.send(false, ConstStr.RESULT_FAILED);
+    }
 }

+ 21 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/TjDao.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import com.example.nngkxxdp.entity.Department;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -263,4 +264,24 @@ public interface TjDao {
     void deleteRecord(Date firstDay, Date lastDay);
 
     void deleteDeptRecord(String thisMonth);
+
+    int getDeptCount(String deptName, Integer is_deleted);
+
+    /**
+     * 通过page,limit分页查询部门的信息
+     *
+     * @param startRows 必须大于等于0
+     * @param limit     必须大于0
+     * @param deptName  部门名称,可以可不填
+     * @return
+     */
+    List<Map<String, Object>> getDeptPage(Integer startRows, Integer limit, String deptName, Integer is_deleted);
+
+    int getChnlidCount(Integer deptid, Integer is_deleted);
+
+    List<Map<String, Object>> getChnlidListByDeptid(int startRows, Integer limit, Integer deptid, Integer is_deleted);
+
+    Department getDepartmentByName(@Param("deptname") String deptname);
+
+    Integer saveDept(Department department);
 }

+ 24 - 11
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/Department.java

@@ -5,7 +5,7 @@ import lombok.Data;
 import java.io.Serializable;
 
 /**
- *(Dept)实体类
+ * (Dept)实体类
  *
  * @author azw
  * @since 2021-09-27
@@ -14,17 +14,30 @@ import java.io.Serializable;
 public class Department implements Serializable {
     private static final long serialVersionUID = -5033799641667809138L;
 
+    //部门id
     private Integer deptid;
-    /**
-     * 部门名称
-     */
+    //部门名称
     private String deptname;
-    /**
-     * 0:街镇 1:部门
-     */
+    //部门分类名称0:街镇 1:部门
     private Boolean sortid;
-    /**
-     * 基础积分
-     */
-    private Integer base_score;
+    //基础积分
+    private Integer baseScore;
+    //部门网址
+    private String deptUrl;
+    //部门简称
+    private String shortName;
+    //分管领导
+    private String leaderperson;
+    //分管领导电话
+    private String leaderphone;
+    //工作人员
+    private String workperson;
+    //工作人员电话
+    private String workphone;
+    //主要领导
+    private String mainLeader;
+    //主要领导电话
+    private String mainLeaderPhone;
+    //逻辑删除(0未删除,1已删除)
+    private Integer isDeleted = 0;
 }

+ 62 - 40
nngkxxdp/src/main/java/com/example/nngkxxdp/service/TjService.java

@@ -1,48 +1,70 @@
 package com.example.nngkxxdp.service;
 
+import com.example.nngkxxdp.entity.Department;
+
 import java.util.List;
 import java.util.Map;
 
-/** 
-* @author Mr.wang
-* @version 1.0.0
-* @date 2021年9月22日 下午7:55:36
-* @Description 
-*/
+/**
+ * @author Mr.wang
+ * @version 1.0.0
+ * @date 2021年9月22日 下午7:55:36
+ * @Description
+ */
 public interface TjService {
 
-	/**
-	 * 门户网站统计
-	 * @return
-	 */
-	Map<String, Object> portalSite();
-	
-	/**
-	 * 其他区县更新情况
-	 * @param urlId
-	 * @return
-	 */
-	Map<String, Object> otherAreas(Integer urlId, Integer type);
-	
-	/**
-	 * 主城九区对比
-	 * @param type
-	 * @return
-	 */
-	Map<String, Object> contrast(Integer type);
-	
-	/**
-	 * 网站评分统计
-	 * @param type 0、月度;1、季度;2、半年;3、年度;
-	 * @param childrenType 月度:1-12月份;季度:0、第一季度;1、1-2季度;2、1-3季度;3、1-4季度; 半年:0、上半年;1、下半年;年度:年份,例:2021
-	 * @param deptId 部门id
-	 * @return
-	 */
-	Map<String, Object> websiteRating(Integer type, Integer childrenType, Integer deptId, Integer hasDept, String month, String newMon);
-	
-	Map<String, Object> task(String strDate);
-	
-	Map<String, Object> sendSms();
-
-	List<Map<String, Object>> newMedia();
+    /**
+     * 门户网站统计
+     *
+     * @return
+     */
+    Map<String, Object> portalSite();
+
+    /**
+     * 其他区县更新情况
+     *
+     * @param urlId
+     * @return
+     */
+    Map<String, Object> otherAreas(Integer urlId, Integer type);
+
+    /**
+     * 主城九区对比
+     *
+     * @param type
+     * @return
+     */
+    Map<String, Object> contrast(Integer type);
+
+    /**
+     * 网站评分统计
+     *
+     * @param type         0、月度;1、季度;2、半年;3、年度;
+     * @param childrenType 月度:1-12月份;季度:0、第一季度;1、1-2季度;2、1-3季度;3、1-4季度; 半年:0、上半年;1、下半年;年度:年份,例:2021
+     * @param deptId       部门id
+     * @return
+     */
+    Map<String, Object> websiteRating(Integer type, Integer childrenType, Integer deptId, Integer hasDept, String month, String newMon);
+
+    Map<String, Object> task(String strDate);
+
+    Map<String, Object> sendSms();
+
+    List<Map<String, Object>> newMedia();
+
+    /**
+     * 通过page,limit分页查询部门的信息
+     *
+     * @param page     必须大于0
+     * @param limit    必须大于0
+     * @param deptName 部门名称,可以可不填
+     * @return
+     */
+    Map<String, Object> getDeptPage(Integer page, Integer limit, String deptName);
+
+    Map<String, Object> getChnlidListByDeptid(Integer page, Integer limit, Integer deptid);
+
+    Map<String, Object> saveDept(Department department);
+
+    Map<String, Object> getDeptById(Integer deptid);
 }

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/ArticleServiceImpl.java

@@ -24,6 +24,7 @@ import com.example.nngkxxdp.util.Blank;
 import com.example.nngkxxdp.util.SendUtil;
 
 import cn.hutool.core.date.DateUtil;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * (Article)表服务实现类
@@ -32,6 +33,7 @@ import cn.hutool.core.date.DateUtil;
  * @since 2021-09-22 19:59:52
  */
 @Service("articleService")
+@Transactional
 public class ArticleServiceImpl implements ArticleService {
     @Resource
     private ArticleDao articleDao;

+ 55 - 3
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/TjServiceImpl.java

@@ -4,6 +4,8 @@ import java.math.BigDecimal;
 import java.util.*;
 
 import com.example.nngkxxdp.dao.HlwInterfaceDao;
+import com.example.nngkxxdp.entity.Department;
+import com.example.nngkxxdp.util.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -13,14 +15,12 @@ import com.alibaba.fastjson.JSONObject;
 import com.example.nngkxxdp.dao.TjDao;
 import com.example.nngkxxdp.dao.UserDao;
 import com.example.nngkxxdp.service.TjService;
-import com.example.nngkxxdp.util.Blank;
-import com.example.nngkxxdp.util.DateUtil;
-import com.example.nngkxxdp.util.NewDeptTaskUtil;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.log.StaticLog;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 
@@ -31,6 +31,7 @@ import javax.annotation.Resource;
  * @Description
  */
 @Service
+@Transactional
 public class TjServiceImpl implements TjService {
 
     @Autowired
@@ -1406,6 +1407,57 @@ public class TjServiceImpl implements TjService {
         return mapList;
     }
 
+    /**
+     * 通过page,limit分页查询部门的信息
+     *
+     * @param page     必须大于0
+     * @param limit    必须大于0
+     * @param deptName 部门名称,可以可不填
+     * @return
+     */
+    @Override
+    public Map<String, Object> getDeptPage(Integer page, Integer limit, String deptName) {
+        int startRows = (page - 1) * limit;
+        int count = tjDao.getDeptCount(deptName, ConstStr.NOT_DELETED);
+        if (count > 0) {
+            return SendUtil.layuiTable(count, tjDao.getDeptPage(startRows, limit, deptName, ConstStr.NOT_DELETED));
+        }
+        return SendUtil.layuiTable(0, null);
+    }
+
+    @Override
+    public Map<String, Object> getChnlidListByDeptid(Integer page, Integer limit, Integer deptid) {
+        int startRows = (page - 1) * limit;
+        int count = tjDao.getChnlidCount(deptid, ConstStr.NOT_DELETED);
+        if (count > 0) {
+            return SendUtil.layuiTable(count, tjDao.getChnlidListByDeptid(startRows, limit, deptid, ConstStr.NOT_DELETED));
+        }
+        return SendUtil.layuiTable(0, null);
+    }
+
+    @Override
+    public Map<String, Object> saveDept(Department department) {
+        if(Blank.isEmpty(department.getDeptname())){
+            return SendUtil.send(true, ConstStr.ADD_FAILED, "部门名称不能为空");
+        }
+        if(Blank.isEmpty(department.getSortid())){
+            return SendUtil.send(true, ConstStr.ADD_FAILED, "部门分类不能为空");
+        }
+        Department oldDepartment = tjDao.getDepartmentByName(department.getDeptname());
+        if (Blank.isEmpty(oldDepartment)) {
+            if (tjDao.saveDept(department) <= 0) {
+                return SendUtil.send(true, ConstStr.ADD_FAILED, "");
+            }
+            return SendUtil.send(true, ConstStr.ADD_SUCCESS, "");
+        }
+        return SendUtil.send(true, ConstStr.ADD_FAILED, "存在相同的部门名称");
+    }
+
+    @Override
+    public Map<String, Object> getDeptById(Integer deptid) {
+        return null;
+    }
+
     private int getArrayIndex(List<String> arr, String obj) {
         for (int j = 0; j < arr.size(); j++) {
             if (obj.equals(arr.get(j))) {

+ 16 - 11
nngkxxdp/src/main/java/com/example/nngkxxdp/util/ConstStr.java

@@ -18,9 +18,8 @@ public class ConstStr {
     public static final String FINISHED = "已办结";
 
 
-
     public static final String VACCINATION = "疫苗接种点";
-    
+
     public static final String VACCINATION_WEEK = "部门镇街“一把手”这周在忙啥";
 
 
@@ -74,13 +73,19 @@ public class ConstStr {
     /**
      * 用户管理
      */
-    public final static String USERNAME_EXIST= "账号名已存在";
-    public final static String ADD_SUCCESS= "新增成功";
-    public final static String ADD_FAILED= "新增失败";
-    public final static String DELETEUSER_SUCCESS= "删除成功";
-    public final static String DELETEUSER_FAILED= "删除失败";
-    public final static String UPDATEUSER_SUCCESS= "编辑成功";
-    public final static String UPDATEUSER_FAILED= "编辑失败";
-    public final static String OLDPASSWORD_FAILED= "原密码输入错误";
-    public final static String NOTEXIST_USER= "没有此用户";
+    public final static String USERNAME_EXIST = "账号名已存在";
+    public final static String ADD_SUCCESS = "新增成功";
+    public final static String ADD_FAILED = "新增失败";
+    public final static String DELETEUSER_SUCCESS = "删除成功";
+    public final static String DELETEUSER_FAILED = "删除失败";
+    public final static String UPDATEUSER_SUCCESS = "编辑成功";
+    public final static String UPDATEUSER_FAILED = "编辑失败";
+    public final static String OLDPASSWORD_FAILED = "原密码输入错误";
+    public final static String NOTEXIST_USER = "没有此用户";
+
+    /**
+     * 逻辑删除,0未删除,1已删除
+     */
+    public final static Integer NOT_DELETED = 0;
+    public final static Integer DELETED = 1;
 }

+ 3 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/WzkpRecordUtil.java

@@ -50,13 +50,16 @@ public class WzkpRecordUtil {
             }
             Date date = DateUtil.parse(dateString, "yyyy-MM-dd");
             Calendar cl = Calendar.getInstance();
+
             cl.setTime(date);
             cl.add(Calendar.MONTH, -1);
             cl.set(Calendar.DAY_OF_MONTH, 1);
+
             Date firstDay = cl.getTime();
             cl.add(Calendar.MONTH, 1);
             cl.add(Calendar.DAY_OF_MONTH, 1);
             cl.add(Calendar.DATE, -1);
+
             Date lastDay = cl.getTime();
             Calendar cl1 = Calendar.getInstance();
             cl1.setTime(date);

+ 108 - 11
nngkxxdp/src/main/resources/mapper/TjDao.xml

@@ -440,9 +440,9 @@
     </select>
 
     <select id="inserDeptChnlid">
-        INSERT INTO t_dept_chnlid(deptid, chnlid) VALUES
+        INSERT INTO t_dept_chnlid(deptid, chnlid,is_deleted) VALUES
         <foreach collection="list" item="item" separator=",">
-            (#{item.deptid}, #{item.chnlid})
+            (#{item.deptid}, #{item.chnlid},0)
         </foreach>
     </select>
 
@@ -468,22 +468,119 @@
                  LEFT JOIN t_dept_chnlid b ON a.deptid = b.deptid
         ORDER BY a.deptid;
     </select>
+    <select id="getDeptCount" resultType="java.lang.Integer">
+        select count(*)
+        from t_dept
+        <where>
+            1=1
+            <if test="deptName != null">
+                AND deptname LIKE CONCAT('%', #{deptName}, '%')
+            </if>
+            <if test="is_deleted != null">
+                AND is_deleted =#{is_deleted}
+            </if>
+        </where>
+    </select>
+    <select id="getDeptPage" resultType="java.util.Map">
+        SELECT
+        deptid,
+        deptname,
+        sortid,
+        base_score,
+        dept_url,
+        short_name,
+        leaderperson,
+        leaderphone,
+        workperson,
+        workphone,
+        main_leader,
+        main_leader_phone
+        FROM t_dept
+        <where>
+            1=1
+            <if test="deptName != null">
+                AND deptname LIKE CONCAT('%', #{deptName}, '%')
+            </if>
+            <if test="is_deleted != null">
+                AND is_deleted =#{is_deleted}
+            </if>
+        </where>
+        limit #{startRows},#{limit}
+    </select>
+
+    <select id="getChnlidCount" resultType="java.lang.Integer">
+        select count(*)
+        from t_dept_chnlid
+        <where>
+            1=1
+            <if test="deptid != null">
+                AND deptid =#{deptid}
+            </if>
+            <if test="is_deleted != null">
+                AND is_deleted =#{is_deleted}
+            </if>
+        </where>
+    </select>
+    <select id="getChnlidListByDeptid" resultType="java.util.Map">
+        SELECT
+        a.id,
+        a.deptid,
+        a.chnlid,
+        b.CHNLIDNAME
+        FROM
+        (
+        SELECT id, deptid, chnlid FROM t_dept_chnlid WHERE 1 = 1
+        <if test="deptid != null">
+            AND deptid =#{deptid}
+        </if>
+        <if test="is_deleted != null">
+            AND is_deleted =#{is_deleted}
+        </if>
+        limit #{startRows},#{limit} ) a
+        LEFT JOIN ( SELECT chnlid, CHNLIDNAME FROM save_hlw_interface_data GROUP BY chnlid ) b ON a.chnlid =
+        b.chnlid
+    </select>
+
+    <select id="getDepartmentByName" resultType="com.example.nngkxxdp.entity.Department">
+        select *
+        from t_dept
+        <where>
+            1=1
+            <if test="deptname != null">
+                AND deptname =#{deptname}
+            </if>
+        </where>
+    </select>
+
+    <insert id="saveDept" parameterType="com.example.nngkxxdp.entity.Department">
+        INSERT INTO t_dept (deptname, sortid, base_score, dept_url, short_name,
+                            leaderperson, leaderphone, workperson, workphone, main_leader,
+                            main_leader_phone, is_deleted)
+        VALUES (#{deptname},
+                #{sortid},
+                #{baseScore},
+                #{deptUrl},
+                #{shortName},
+                #{leaderperson},
+                #{leaderphone},
+                #{workperson},
+                #{workphone},
+                #{mainLeader},
+                #{mainLeaderPhone},
+                #{isDeleted})
+    </insert>
 
     <delete id="deleteRecord">
         DELETE
-        FROM
-            t_record
-        WHERE
-            create_time BETWEEN #{firstDay}
-                AND #{lastDay};
+        FROM t_record
+        WHERE create_time BETWEEN #{firstDay}
+                  AND #{lastDay};
     </delete>
 
     <delete id="deleteDeptRecord">
         DELETE
-        FROM
-            t_dept_record
-        WHERE
-            month_time = #{thisMonth};
+        FROM t_dept_record
+        WHERE month_time = #{thisMonth};
     </delete>
 
 </mapper>