Browse Source

项目状态筛选

wucl 2 years ago
parent
commit
a480a82d67

+ 6 - 5
biz-base/src/main/java/com/dayou/controller/ItemController.java

@@ -3,6 +3,7 @@ package com.dayou.controller;
 import com.dayou.dto.ItemDTO;
 import com.dayou.vo.DepartmentStatVO;
 import com.dayou.vo.ItemStatVO;
+import com.dayou.vo.ItemVO;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,8 +42,8 @@ public class ItemController extends BaseController {
     * 项目信息表列表
     */
     @GetMapping("")
-    public RestResponse<Page<Item>> page(Item item, Page page,Boolean me){
-        Page<Item> pages=itemService.selectPage(page,item,me);
+    public RestResponse<Page<ItemVO>> page(Item item, Page page, Boolean me){
+        Page<ItemVO> pages=itemService.selectPage(page,item,me);
         return RestResponse.data(pages);
     }
 
@@ -50,9 +51,9 @@ public class ItemController extends BaseController {
      * 项目信息表详情
      */
     @GetMapping("/{id}")
-    public RestResponse<ItemDTO> detail(@PathVariable Long id){
-        ItemDTO itemDTO =itemService.detail(id);
-        return RestResponse.data(itemDTO);
+    public RestResponse<ItemVO> detail(@PathVariable Long id){
+        ItemVO itemVO =itemService.detail(id);
+        return RestResponse.data(itemVO);
      }
 
     /**

+ 2 - 2
biz-base/src/main/java/com/dayou/controller/ItemStageController.java

@@ -108,8 +108,8 @@ public class ItemStageController extends BaseController {
      * @return
      */
     @GetMapping("/list")
-    public RestResponse<List<List<ItemStageVO>>> stageList(){
-        List<List<ItemStageVO>> list = itemStageService.stageList();
+    public RestResponse<List<List<ItemStageVO>>> stageList(String state){
+        List<List<ItemStageVO>> list = itemStageService.stageList(state);
         return RestResponse.data(list);
     }
 }

+ 3 - 2
dao/src/main/java/com/dayou/mapper/ItemMapper.java

@@ -5,6 +5,7 @@ import com.dayou.dto.ItemDTO;
 import com.dayou.entity.Item;
 import com.dayou.dao.CustomBaseMapper;
 import com.dayou.vo.ItemStatVO;
+import com.dayou.vo.ItemVO;
 import org.apache.ibatis.annotations.Param;
 
 /**
@@ -19,7 +20,7 @@ public interface ItemMapper extends CustomBaseMapper<Item> {
 
     ItemStatVO stat();
 
-    ItemDTO xDetail(@Param("id") Long id);
+    ItemVO xDetail(@Param("id") Long id);
 
-    Page<Item> getPage(Page page, @Param("item") Item item, @Param("userId") Long userId);
+    Page<ItemVO> getPage(Page page, @Param("item") Item item, @Param("userId") Long userId);
 }

+ 14 - 14
dao/src/main/resources/mapper/ItemMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.dayou.mapper.ItemMapper">
 
     <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.dayou.dto.ItemDTO">
+    <resultMap id="BaseResultMap" type="com.dayou.vo.ItemVO">
         <result column="id" property="id" />
         <result column="deleted" property="deleted" />
         <result column="created" property="created" />
@@ -21,16 +21,17 @@
         <result column="payment_method" property="paymentMethod" />
         <result column="amount" property="amount" />
         <result column="state" property="state" />
+        <result column="department_id" property="departmentId" />
         <collection property="userIds" ofType="java.lang.Long" select="selectItemUserId" column="id"/>
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id,
-        deleted,
-        created,
-        modified,
-        business_no, oa_no, name, business_source, client_unit, client_name, mobile, client_manager, skiller, sign_date, payment_method, amount, state
+        i.id,
+        i.deleted,
+        i.created,
+        i.modified,
+        i.business_no, i.oa_no, i.name, i.business_source, i.client_unit, i.client_name, i.mobile, i.client_manager, i.skiller, i.sign_date, i.payment_method, i.amount, i.state,i.department_id
     </sql>
 
     <select id="stat" resultType="com.dayou.vo.ItemStatVO">
@@ -45,23 +46,22 @@
     </select>
 
     <select id="xDetail" parameterType="java.lang.Long" resultMap="BaseResultMap">
-        select <include refid="Base_Column_List"/> from item where deleted = 0 and id =#{id}
+        select <include refid="Base_Column_List"/>, d.name as departmentName from item i left join department d on d.id = i.department_id where i.deleted = 0 and d.deleted=0 and i.id =#{id}
     </select>
 
     <select id="selectItemUserId" parameterType="java.lang.Long" resultType="java.lang.Long">
         select user_id from item_user where item_id = #{id}
     </select>
 
-    <select id="getPage" resultType="com.dayou.entity.Item">
+    <select id="getPage" resultType="com.dayou.vo.ItemVO">
         SELECT
-            <include refid="Base_Column_List"/>
+            <include refid="Base_Column_List"/> , d.name as departmentName
         FROM
-            item i
+            item i left join department d on i.department_id = d.id
         WHERE
-        deleted = 0
-        <if test="item!=null and item.state!=null and item.state!='' ">
-            and i.state = #{item.state}
-        </if>
+        i.deleted = 0
+        and
+        d.deleted = 0
         <if test="item!=null and item.name!=null and item.name!='' ">
             and i.name like concat ('%',#{item.name},'%')
         </if>

+ 3 - 3
dao/src/main/resources/mapper/ItemStageMapper.xml

@@ -35,9 +35,9 @@
     <select id="listByItemId" parameterType="java.lang.Long" resultType="com.dayou.vo.ItemStageVO">
         SELECT
         <include refid="Base_Column_List" />
-        (case when (now() &lt; start_date)=1 then '未开始'
-        when (now() &gt;= start_date and now() &lt;= end_date)=1 then '进行中'
-        when (now() &gt; end_date)=1 then '已完成'
+        (case when (curdate() &lt; start_date)=1 then '未开始'
+        when (curdate() &gt;= start_date and curdate() &lt;= end_date)=1 then '进行中'
+        when (curdate() &gt; end_date)=1 then '已完成'
         else '' end) as state,
         (select name from user where deleted = 0 and id = s.dutyer_id) AS dutyer,
         (select name from item where deleted =0 and id =s.item_id) AS itemName

+ 1 - 0
domain/src/main/java/com/dayou/dto/ItemDTO.java

@@ -19,4 +19,5 @@ public class ItemDTO extends Item {
      * 项目配置人员id列表
      */
     private List<Long> userIds;
+
 }

+ 6 - 3
domain/src/main/java/com/dayou/entity/Item.java

@@ -107,11 +107,14 @@ public class Item extends BaseEntity {
     private BigDecimal amount;
 
     /**
-     * 状态
+     * 状态 (已作废)
      */
-    @ImportCell
-    @ExportCell(columnName = "状态")
     private String state;
 
+    /**
+     * 所属部门
+     */
+    private Long departmentId;
+
 
 }

+ 40 - 0
domain/src/main/java/com/dayou/enums/ItemStateEnum.java

@@ -0,0 +1,40 @@
+package com.dayou.enums;
+
+import org.springframework.util.StringUtils;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2022/12/30
+ * created with IntelliJ IDEA.
+ */
+public enum ItemStateEnum {
+
+    PENDING("进行中"),
+    COMPLETED("已完成"),
+    UNPLAYED("未开始")
+    ;
+
+    private String name;
+
+    ItemStateEnum(String name) {
+        this.name = name;
+    }
+
+    public static ItemStateEnum getName(String name) {
+        if ("进行中".equals(name)){
+            return PENDING;
+        }
+        if ("已完成".equals(name)){
+            return COMPLETED;
+        }if ("未开始".equals(name)){
+            return UNPLAYED;
+        }
+        return null;
+    }
+
+    public String getName() {
+        return name;
+    }
+}

+ 24 - 0
domain/src/main/java/com/dayou/vo/ItemVO.java

@@ -0,0 +1,24 @@
+package com.dayou.vo;
+
+import com.dayou.entity.Item;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 类说明:
+ *
+ * @author: wucl
+ * @since: 2022/12/30
+ * created with IntelliJ IDEA.
+ */
+@Data
+public class ItemVO extends Item {
+
+    private String departmentName;
+
+    /**
+     * 项目配置人员id列表
+     */
+    private List<Long> userIds;
+}

+ 3 - 2
service/src/main/java/com/dayou/service/IItemService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.dayou.vo.ItemStatVO;
+import com.dayou.vo.ItemVO;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
 /**
@@ -17,9 +18,9 @@ import org.springframework.web.multipart.MultipartFile;
  */
 public interface IItemService extends IService<Item> {
 
-        Page<Item> selectPage(Page page,Item item,Boolean me);
+        Page<ItemVO> selectPage(Page page, Item item, Boolean me);
 
-        ItemDTO detail(Long id);
+        ItemVO detail(Long id);
 
         Boolean add(ItemDTO itemDTO);
 

+ 1 - 1
service/src/main/java/com/dayou/service/IItemStageService.java

@@ -31,5 +31,5 @@ public interface IItemStageService extends IService<ItemStage> {
 
     List<ItemStageVO> listByItemId(Long itemId);
 
-    List<List<ItemStageVO>> stageList();
+    List<List<ItemStageVO>> stageList(String state);
 }

+ 48 - 6
service/src/main/java/com/dayou/service/impl/ItemServiceImpl.java

@@ -3,13 +3,18 @@ package com.dayou.service.impl;
 import com.dayou.dto.ItemDTO;
 import com.dayou.entity.Item;
 import com.dayou.entity.ItemUser;
+import com.dayou.enums.ItemStateEnum;
 import com.dayou.mapper.ItemMapper;
 import com.dayou.mapper.ItemUserMapper;
 import com.dayou.service.IItemService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dayou.service.IItemStageService;
 import com.dayou.service.IItemUserService;
 import com.dayou.utils.LoginContext;
+import com.dayou.vo.ItemStageVO;
 import com.dayou.vo.ItemStatVO;
+import com.dayou.vo.ItemVO;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -26,6 +31,8 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
+
+import java.time.LocalDate;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Set;
@@ -51,21 +58,29 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
     @Autowired
     private ItemMapper itemMapper;
 
+    @Autowired
+    private IItemStageService itemStageService;
+
     @Override
     @SuppressWarnings("unchecked")
-    public Page<Item> selectPage(Page page,Item item,Boolean me){
+    public Page<ItemVO> selectPage(Page page, Item item, Boolean me){
         Long userId = null;
         if (me){
             userId = LoginContext.getUserId();
         }
-        return itemMapper.getPage(page,item,userId);
-    }
+        Page<ItemVO> result = itemMapper.getPage(page, item, userId);
+        List<ItemVO> records = result.getRecords();
+        records.stream().forEach(x->{
+            x.setState(getItemState(x.getId()));
+        });
+        return result;
 
+    }
 
     @Override
-    public ItemDTO detail(Long id){
-        ItemDTO itemDTO = itemMapper.xDetail(id);
-        return itemDTO;
+    public ItemVO detail(Long id){
+        ItemVO itemVO = itemMapper.xDetail(id);
+        return itemVO;
     }
 
     @Transactional
@@ -107,4 +122,31 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
     public ItemStatVO stat() {
         return itemMapper.stat();
     }
+
+    /**
+     * 获取项目状态
+     * @param id 项目id
+     * @return
+     */
+    private String getItemState(Long id){
+        List<ItemStageVO> itemStageVOS = itemStageService.listByItemId(id);
+        if (CollectionUtils.isNotEmpty(itemStageVOS)){
+            LocalDate startDate = itemStageVOS.get(0).getStartDate();
+            LocalDate endDate = itemStageVOS.get(itemStageVOS.size() - 1).getEndDate();
+            LocalDate now = LocalDate.now();
+            if ((now.isAfter(startDate) || now.isEqual(startDate))
+                    &&
+                    (now.isBefore(endDate) || now.isEqual(endDate))){
+                return ItemStateEnum.PENDING.getName();
+            }
+            if (now.isAfter(endDate)){
+                return ItemStateEnum.COMPLETED.getName();
+            }
+
+            if (now.isBefore(startDate)){
+                return ItemStateEnum.UNPLAYED.getName();
+            }
+        }
+        return ItemStateEnum.UNPLAYED.getName();
+    }
 }

+ 33 - 3
service/src/main/java/com/dayou/service/impl/ItemStageServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
 import com.dayou.common.BaseEntity;
 import com.dayou.entity.Item;
 import com.dayou.entity.ItemStage;
+import com.dayou.enums.ItemStateEnum;
 import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.ItemMapper;
 import com.dayou.mapper.ItemStageMapper;
@@ -12,6 +13,7 @@ import com.dayou.service.IItemStageService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dayou.vo.ItemStageVO;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.ibatis.annotations.Case;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -30,6 +32,7 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -139,13 +142,40 @@ public class ItemStageServiceImpl extends ServiceImpl<ItemStageMapper, ItemStage
     }
 
     @Override
-    public List<List<ItemStageVO>> stageList() {
+    public List<List<ItemStageVO>> stageList(String state) {
         List<List<ItemStageVO>> list = new ArrayList<>();
-        List<Long> itemIds = itemMapper.selectList(new LambdaQueryWrapper<Item>().eq(BaseEntity::getDeleted, false)).stream().map(BaseEntity::getId).collect(Collectors.toList());
+        List<Long> itemIds = itemMapper.selectList(new LambdaQueryWrapper<Item>()
+                        .eq(BaseEntity::getDeleted, false))
+                .stream().map(BaseEntity::getId)
+                .collect(Collectors.toList());
         itemIds.stream().forEach(x->{
             List<ItemStageVO> itemStageVOS = listByItemId(x);
             if (CollectionUtils.isNotEmpty(itemStageVOS)){
-                list.add(itemStageVOS);
+                LocalDate startDate = itemStageVOS.get(0).getStartDate();
+                LocalDate endDate = itemStageVOS.get(itemStageVOS.size() - 1).getEndDate();
+                LocalDate now = LocalDate.now();
+                ItemStateEnum stateEnum = ItemStateEnum.getName(state);
+                switch (stateEnum){
+                    case PENDING:
+                        if ((now.isAfter(startDate) || now.isEqual(startDate))
+                                &&
+                                (now.isBefore(endDate) || now.isEqual(endDate))){
+                            list.add(itemStageVOS);
+                        }
+                        break;
+                    case COMPLETED:
+                        if (now.isAfter(endDate)){
+                            list.add(itemStageVOS);
+                        }
+                        break;
+                    case UNPLAYED:
+                        if (now.isBefore(startDate)){
+                            list.add(itemStageVOS);
+                        }
+                        break;
+                    default:
+
+                }
             }
         });
         return list;

+ 2 - 1
sql/20221229.sql

@@ -1 +1,2 @@
-alter table user add column password_state bit(1) not null default 1 comment '初始密码状态';
+alter table user add column password_state bit(1) not null default 1 comment '初始密码状态';
+ALTER table item add COLUMN department_id BIGINT(20) comment '所属部门';