Browse Source

财务结算-政策列表修改

yangzian 3 years ago
parent
commit
20ecdb2aee

+ 53 - 103
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/controller/CwjsPolicyInfoController.java

@@ -28,10 +28,7 @@ import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.ctop.finance.policy.entity.*;
-import org.jeecg.ctop.finance.policy.mapper.CwjsCompanyApprovalUserMapper;
-import org.jeecg.ctop.finance.policy.mapper.CwjsCompanySubjectMapper;
-import org.jeecg.ctop.finance.policy.mapper.CwjsPolicyApprovalLogMapper;
-import org.jeecg.ctop.finance.policy.mapper.CwjsSaleAssistantInfoMapper;
+import org.jeecg.ctop.finance.policy.mapper.*;
 import org.jeecg.ctop.finance.policy.service.*;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
@@ -80,6 +77,8 @@ public class CwjsPolicyInfoController {
 	 @Resource
 	 CwjsCompanyApprovalUserMapper companyApprovalUserMapper;
 	 @Resource
+	 CwjsPolicyInfoMapper cwjsPolicyInfoMapper;
+	 @Resource
 	 CwjsCompanySubjectMapper companySubjectMapper;
 	 @Autowired
 	 ICwjsCompanySubjectService companySubjectService;
@@ -265,7 +264,7 @@ public class CwjsPolicyInfoController {
 	 */
 	@ApiOperation(value="政策信息表-分页列表查询", notes="政策信息表-分页列表查询")
 	@GetMapping(value = "/list")
-	public Result<PageInfo<CwjsPolicyInfo>> queryPageList(CwjsPolicyInfo cwjsPolicyInfo,
+	public Result queryPageList(CwjsPolicyInfo cwjsPolicyInfo,
 									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
 									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
 									  @RequestParam(name="userId") String userId,
@@ -273,114 +272,77 @@ public class CwjsPolicyInfoController {
 
 		//查询用户角色
         String roleCode = roleService.getRoleCodeByUserId(userId);
-        //查看用户是否为审核人员
-        List<CwjsCompanyApprovalUser> cwjsCompanyApprovalUserList = companyApprovalUserMapper.queryByUserId(userId);
-        //查询政策
-		List<CwjsPolicyInfo> cwjsPolicyInfoList = cwjsPolicyInfoService.queryPageList(cwjsPolicyInfo);
-		if(Check.isNull(cwjsPolicyInfoList)){
-			PageInfo<CwjsPolicyInfo> pageInfo = new PageInfo<>(cwjsPolicyInfoList);
-			return Result.successMsg("目前没有政策。",pageInfo);
-		}
-        /**如果是管理员,就全部看,该搜索搜索,不搜索就全看*/
 
-		List<String> res = new ArrayList<>();
+
+		List<String> userIds = new ArrayList<>();
 		if ("admin".equalsIgnoreCase(roleCode) || "finance".equalsIgnoreCase(roleCode) ){
 
 		}else if("saleDirector".equalsIgnoreCase(roleCode)){
 			//总监 看下属
-			res = cwjsPolicyInfoService.getAllSubordinate(userId);
-			// 与自己有 关联的人员
-			//List<String> sale = cwjsSaleAssistantInfoService.getCwSaleAndAssistantListStr(userId);
-			// 自己部门下的所有人员
-			//List <CwjsSaleAssistantInfo> saleList = cwjsSaleAssistantInfoMapper.getSaleListByUserDepart(userId);
-			//List<String> sale = saleList.stream().map(CwjsSaleAssistantInfo::getSaleId).collect(Collectors.toList());
-			//res.addAll(sale);
+			userIds = cwjsPolicyInfoService.getAllSubordinate(userId);
+
+		//法务
+		}else if("legalAffairs".equalsIgnoreCase(roleCode)){
+			//法务 查看 华北
+			cwjsPolicyInfo.setCompanySubjectId(1);
 		}else {
 			//查询 对应的销售或 助理
-			res = cwjsSaleAssistantInfoService.getCwSaleAndAssistantListStr(userId);
-			if (Check.isNull(res)){
-				res.add(userId);
+			userIds = cwjsSaleAssistantInfoService.getCwSaleAndAssistantListStr(userId);
+			if (Check.isNull(userIds)){
+				userIds.add(userId);
 			}
+
 		}
+		cwjsPolicyInfo.setSaleIds(userIds);
 
-		List<String> userIds = new ArrayList<>();
 
-		userIds.addAll(res);
-
-        /**如果不是管理员,也不是审核人员。
-		 * (看自己和自己下属的所有政策)  修改为 销售-助理 关联关系查看。
-		 * */
-        if(!"admin".equalsIgnoreCase(roleCode) && !"finance".equalsIgnoreCase(roleCode) && Check.isNull(cwjsCompanyApprovalUserList)){
-			//Set<String> userIds= materialReportOverViewService.recursiveQuerySubordinate(userId);
-			//List<String> userIds = cwjsPolicyInfoService.getAllSubordinate(userId);
-			List<CwjsPolicyInfo> removeList = new ArrayList<>();
-            cwjsPolicyInfoList.forEach(cwjsPolicy -> {
-                if(!userIds.contains(cwjsPolicy.getCreateUserId())){
-                    removeList.add(cwjsPolicy);
-                }
-            });
-            cwjsPolicyInfoList.removeAll(removeList);
-        }
-        /**如果不是管理员,是审核人员。看自己创建的和自己下属的所有政策、和该自己审核。*/
-        if(!"admin".equalsIgnoreCase(roleCode) && !"finance".equalsIgnoreCase(roleCode) && !Check.isNull(cwjsCompanyApprovalUserList)){
-//			Set<String> userIds= materialReportOverViewService.recursiveQuerySubordinate(userId);
-			//List<String> userIds = cwjsPolicyInfoService.getAllSubordinate(userId);
-			List<CwjsPolicyInfo> removeList = new ArrayList<>();
-			List<String> subList = cwjsCompanyApprovalUserList.stream().map(CwjsCompanyApprovalUser::getCompanySubjectId).collect(Collectors.toList());
-            //政策的主体 不是 审核人的主体 过滤 只保留 和审核人 是一样的主体的 政策
-			cwjsPolicyInfoList.forEach(cwjsPolicy -> {
-                //if(!userIds.contains(cwjsPolicy.getCreateUserId()) && !userId.equalsIgnoreCase(cwjsPolicy.getApprovedProgress())){
-                if(!subList.contains(String.valueOf(cwjsPolicy.getCompanySubjectId())) && !userIds.contains(cwjsPolicy.getCreateUserId())){
-                    removeList.add(cwjsPolicy);
-                }
-            });
-            cwjsPolicyInfoList.removeAll(removeList);
-        }
+        //查询政策
+		List<CwjsPolicyInfo> cwjsPolicyInfoList = cwjsPolicyInfoService.queryPageList(cwjsPolicyInfo);
+		if(Check.isNull(cwjsPolicyInfoList)){
+			return Result.successMsg("没有符合条件的政策,请重新选择。",null);
+		}
+
 
-		cwjsPolicyInfoList.sort((CwjsPolicyInfo o1, CwjsPolicyInfo o2) -> o2.getCreateTime().after(o1.getCreateTime()) ? 1 : -1 );
 		List<CwjsPolicyInfo> cwjsPolicyInfos = ListPageUtil.page(cwjsPolicyInfoList, pageSize, pageNo);
 
 		cwjsPolicyInfos.forEach(cwjsPolicy ->{
 			CwjsPolicyApprovalLog log = policyApprovalLogMapper.getOneByPolicyId(cwjsPolicy.getId(),1);	// 查询 被拒 审核意见 最新的一条
-			if(!Check.isNull(log)){
-				cwjsPolicy.setApprovalContent(log.getApprovalContent());
-			}
+			cwjsPolicy.setApprovalContent(Check.isNull(log) ? "暂无被拒意见" : log.getApprovalContent());
+
 			CwjsPolicyApprovalLog bossContent = policyApprovalLogMapper.getOneByPolicyId(cwjsPolicy.getId(),2);	// 查询 转发领导的 审核意见 最新的一条
-			cwjsPolicy.setTheBossContent(Check.isNull(bossContent) ? "" : bossContent.getApprovalContent());
+			cwjsPolicy.setTheBossContent(Check.isNull(bossContent) ? "暂无老板审核意见" : bossContent.getApprovalContent());
 
-			//根据主体查询 最后一个审核人员
-			CwjsCompanyApprovalUser approvalUser = companyApprovalUserMapper.getEndApprovalUserBySub(cwjsPolicy.getCompanySubjectId());
-			//政策当前审核人 = 最后一个审核人 = 当前用户   && 状态不为3 审核通过  && 状态不为4 审核拒绝  ||  当前用户 不是老板
-			// 则显示 转领导审批
-
-			if(cwjsPolicy.getApprovedStatus() != 3 && cwjsPolicy.getApprovedStatus() != 4){
-				if (cwjsPolicy.getApprovedProgress().equals(approvalUser.getApprovalUserId()) && approvalUser.getApprovalUserId().equals(userId)
-						&& !"4aba62011120ac565c7f2b9f8f4aa96b".equals(userId)){
-					cwjsPolicy.setTheBossRight("yes");
-				}
-			}else {
-				cwjsPolicy.setTheBossRight("no");
-			}
+			CwjsPolicyApprovalLog legalContent = policyApprovalLogMapper.getOneByPolicyId(cwjsPolicy.getId(),11);	// 查询 法务 审核意见 最新的一条
+			cwjsPolicy.setLegalAffairsContent(Check.isNull(legalContent) ? "暂无法务审核意见" : legalContent.getApprovalContent());
 
 
+			String directorUserId = "";
+			//主体为1 为 华北
+			if (cwjsPolicy.getCompanySubjectId() == 1){
+				//查询 该销售 所属的审核人员
+				//华北审核人员 - 法务==>销售总监(销售上级)==>手动转领导/自动转领导
+				directorUserId = cwjsPolicyInfoMapper.getUserLeaderAndDirectorByRoleName(userId,"法务").getString("leaderId");
 
+			}else {
+				//查询 该销售 所属的审核人员
+				//华南审核人员 - 销售总监(销售上级) ==> 分公司经理 ==>转领导
+				directorUserId = cwjsPolicyInfoMapper.getUserLeaderAndDirectorByRoleName(userId,"分公司总经理").getString("directorId");
+
+			}
+
+				//政策当前审核人 = 最后一个审核人 = 当前用户   && 状态不为3 审核通过  && 状态不为4 审核拒绝  ||  当前用户 不是老板
+				// 则显示 转领导审批
+				if(cwjsPolicy.getApprovedStatus() != 3 && cwjsPolicy.getApprovedStatus() != 4){
+					if (cwjsPolicy.getApprovedProgress().equals(directorUserId) && directorUserId.equals(userId)
+							&& !"80e747cdea6f41dbbc8cde23046fd4e0".equals(userId)){
+						cwjsPolicy.setTheBossRight("yes");
+					}
+				}else {
+					cwjsPolicy.setTheBossRight("no");
+				}
 
-			//所有人只要能看到就能有查看的按钮
-          /*  cwjsPolicy.setOperation("查看");
 
-			//查询 对应的销售或 助理
-			List <String> assistantList = cwjsSaleAssistantInfoService.getCwSaleAndAssistantListStr(cwjsPolicy.getCreateUserId());
-			if((assistantList.contains(userId) || assistantList.contains(cwjsPolicy.getCreateUserId())) && cwjsPolicy.getApprovedStatus() == 4){ //创建人是自己且状态是审核拒绝的
-                cwjsPolicy.setOperation("查看|编辑|提交审核");
-            }
 
-			if(userId.equals(cwjsPolicy.getApprovedProgress()) && (cwjsPolicy.getApprovedStatus() == 1 || cwjsPolicy.getApprovedStatus() == 2)){
-                cwjsPolicy.setOperation("查看|审核通过|审核拒绝");
-            }
-			if(userId.equals(cwjsPolicy.getApprovedProgress()) && cwjsPolicy.getApprovedStatus() == 4 && !userId.equals(cwjsPolicy.getCreateUserId())){
-                cwjsPolicy.setOperation("查看");
-            }
-*/
 			StringBuilder stringBuilder = new StringBuilder();
 
 			//审核拒绝
@@ -388,7 +350,7 @@ public class CwjsPolicyInfoController {
 				//有 销售-助理 关联的人员 都可以编辑
 				if(!"admin".equalsIgnoreCase(roleCode) && !"finance".equalsIgnoreCase(roleCode)){
 					List <String> saleOrAssis = cwjsSaleAssistantInfoService.getCwSaleAndAssistantListStr(userId);
-					if(saleOrAssis.contains(cwjsPolicy.getCreateUserId())){
+					if(saleOrAssis.contains(cwjsPolicy.getSaleId())){
 						stringBuilder.append("编辑").append("|").append("提交审核").append("|");
 					}
 				}
@@ -399,24 +361,12 @@ public class CwjsPolicyInfoController {
 					stringBuilder.append("审核通过").append("|").append("审核拒绝").append("|");
 				}
 			}
-		//审核通过
-			/*if (cwjsPolicy.getApprovedStatus() == 3){
-					stringBuilder.append("查看");
-			}*/
+
 			stringBuilder.append("查看").append("|");
 			cwjsPolicy.setOperation(stringBuilder.deleteCharAt(stringBuilder.lastIndexOf("|")).toString());
 
 
 
-			// 用户 公司
-			UserCompany userCompany = userCompanyService.getByUserId(cwjsPolicy.getCreateUserId());
-			if(!Check.isNull(userCompany) && Check.isNull(cwjsPolicy.getCreateUserName())){
-				cwjsPolicy.setCreateUserName(userCompany.getUserName());
-			}
-			//主体 以及 区域
-			CwjsCompanySubject cwjsCompanySubject = companySubjectService.getById(cwjsPolicy.getCompanySubjectId());
-			cwjsPolicy.setCompanySubjectName(cwjsCompanySubject.getCompanySubjectName());
-			cwjsPolicy.setAreaInfo(cwjsCompanySubject.getAreaInfo());
 		});
 		PageInfo<CwjsPolicyInfo> pageInfo = new PageInfo<>(cwjsPolicyInfos);
 		pageInfo.setTotal(cwjsPolicyInfoList.size());

+ 14 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/entity/CwjsPolicyInfo.java

@@ -116,6 +116,17 @@ public class CwjsPolicyInfo implements Serializable{
 	@Excel(name = "创建人名字", width = 15)
 	@ApiModelProperty(value = "创建人名字")
 	private String createUserName;
+
+
+	@ApiModelProperty(value = "销售id")
+	private String saleId;
+	@TableField(exist = false)
+	private List<String> saleIds;
+
+	@TableField(exist = false)
+	@ApiModelProperty(value = "销售姓名")
+	private String saleName;
+
 	/**创建时间*/
     @ApiModelProperty(value = "创建时间")
 	private Date createTime;
@@ -157,4 +168,7 @@ public class CwjsPolicyInfo implements Serializable{
 	/* 给老板审核的理由*/
 	@TableField(exist = false)
 	private String theBossContent;
+	/* 法务审核意见*/
+	@TableField(exist = false)
+	private String legalAffairsContent;
 }

+ 10 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/CwjsPolicyInfoMapper.java

@@ -15,6 +15,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @version V1.0
  */
 public interface CwjsPolicyInfoMapper extends BaseMapper<CwjsPolicyInfo> {
+
+    //查看政策列表
     List<CwjsPolicyInfo> selectPolicyInfos(CwjsPolicyInfo policyInfo);
 
     List<JSONObject> getAllSale();
@@ -32,4 +34,12 @@ public interface CwjsPolicyInfoMapper extends BaseMapper<CwjsPolicyInfo> {
     void updatePolicyInfoById(CwjsPolicyInfo policyInfo);
 
     CwjsPolicyInfo getPolicyInfo(CwjsPolicyInfo policyInfo);
+
+
+
+
+    //查询用户所属公司及区域 以及 上级领导 和 分公司负责人
+    JSONObject getUserLeaderAndDirectorByRoleName(@Param("userId") String userId,@Param("roleName") String roleName);
+
+
 }

+ 84 - 11
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/mapper/xml/CwjsPolicyInfoMapper.xml

@@ -1,8 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.ctop.finance.policy.mapper.CwjsPolicyInfoMapper">
+
+
+    <!-- 查看政策列表 -->
     <select id="selectPolicyInfos" resultType="org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo">
-        select t1.policy_product_name as productName,t2.* from ctop_cwjs_policy_product t1 LEFT JOIN ctop_cwjs_policy_info t2 on t1.policy_id = t2.id
+        select t1.policy_product_name as productName,t2.* ,
+               (select u.realname from sys_user u where u.id = t2.sale_id) as saleName,
+                sub.company_subject_name CompanySubjectName
+        from ctop_cwjs_policy_product t1
+            LEFT JOIN ctop_cwjs_policy_info t2 on t1.policy_id = t2.id
+        LEFT JOIN ctop_cwjs_company_subject sub on sub.id = t2.company_subject_id
         where t1.del_flag = 0 and t2.del_flag = 0
         <if test="companyName != null and companyName != ''">and t2.company_name like concat(concat('%',#{companyName}),'%')</if>
         <if test="advertiserName != null and advertiserName != ''">and t2.advertiser_name like concat(concat('%',#{advertiserName}),'%')</if>
@@ -10,21 +18,36 @@
         <if test="dianPayCompanyName != null and dianPayCompanyName != ''">and t2.dian_pay_company_name like concat(concat('%',#{dianPayCompanyName}),'%')</if>
         <if test="mediaType != null">and t2.media_type = #{mediaType}</if>
         <if test="rebateType != null">and t2.rebate_type = #{rebateType}</if>
-        <if test="createUserId != null and createUserId != ''">and t2.create_user_id = #{createUserId}</if>
-        <if test="createUserName != null and createUserName != ''">and t2.create_user_name = #{createUserName}</if>
-        <if test="createUserIds != null and createUserIds != ''">and  t2.create_user_id in
-         <foreach item="item" index="index" collection="createUserIds" open="(" separator="," close=")">
-            #{item}
-        </foreach></if>
-        <if test="companySubjectIds != null and companySubjectIds != ''">and  t2.company_subject_id in
-            <foreach item="item" index="index" collection="companySubjectIds" open="(" separator="," close=")">
+
+
+        <if test="saleIds != null and saleIds.size() > 0">
+            and  (t2.sale_id in
+            <foreach item="item" index="index" collection="saleIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+            or  t2.create_user_id in
+            <foreach item="item" index="index" collection="saleIds" open="(" separator="," close=")">
                 #{item}
-            </foreach></if>
+            </foreach>
+                )
+        </if>
+
+        <if test="approvedProgress != null and approvedProgress != ''">
+          and t2.approved_progress = #{approvedProgress}
+        </if>
+
+        <if test="companySubjectId != null and companySubjectId != ''">
+          and t2.company_subject_id = #{companySubjectId}
+        </if>
+
+
         <if test="promotionType != null">and t2.promotion_type = #{promotionType}</if>
         <if test="approvedStatus != null and approvedStatus != ''">and t2.approved_status = #{approvedStatus}</if>
         <if test="startTime != null and startTime != ''">and t2.create_time &gt;= #{startTime}</if>
         <if test="endTime != null and endTime != ''">and t2.create_time &lt;= concat(#{endTime},' 23:59:59')</if>
-        <if test="approvedProgress != null and approvedProgress != ''">and t2.approved_progress = #{approvedProgress}</if>
+
+
+
         <if test="policyStartDate != null and policyStartDate != '' and policyEndDate != null and policyEndDate != ''">
         and ((#{policyStartDate} &lt;= t2.policy_start_date and #{policyEndDate} &gt;= t2.policy_start_date)
         or (#{policyStartDate} &gt;= t2.policy_start_date and #{policyStartDate} &lt;= t2.policy_end_date))
@@ -129,6 +152,7 @@
              policy_start_date = #{policyStartDate},
              policy_end_date = #{policyEndDate},
              remarks = #{remarks},
+             sale_id = #{saleId},
              create_user_id = #{createUserId},
              create_user_name = #{createUserName}
         where id = #{id}
@@ -215,6 +239,55 @@
 
 
 
+    <!-- 查询用户所属公司及区域 以及 上级领导 和 分公司负责人 -->
+    <select id="getUserLeaderAndDirectorByRoleName" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            a.company_id companyId,
+            a.company_name companyName,
+            a.nick_name areaName,
+            a.leader_id leaderId,
+            a.leader_name leaderName,
+            b.realname directorName,
+            b.role_code directorRoleCode,
+            b.user_id directorId
+        FROM
+            (
+                SELECT
+                    c.company_id,
+                    c.company_name,
+                    c.nick_name,
+                    u.leader_id,
+                    u.leader_name
+                FROM
+                    `user_company` c
+                        LEFT JOIN sys_user u on c.user_id = u.id
+                WHERE
+                    user_id = #{userId}
+            ) a LEFT JOIN
+            (
+                SELECT
+                    sr.role_name,
+                    sr.role_code,
+                    sur.user_id ,
+                    su.realname,
+                    uc.company_id,
+                    uc.company_name,
+                    uc.nick_name
+                FROM
+                    sys_user_role sur
+                        LEFT JOIN sys_role sr ON sur.role_id = sr.id
+                        LEFT JOIN user_company uc on uc.user_id = sur.user_id
+                        LEFT JOIN sys_user su on su.id = uc.user_id
+                WHERE
+                    sr.role_name = #{roleName}
+            )b
+            on a.company_id = b.company_id
+            limit 1
+    </select>
+
+
+
+
 
 
 

+ 10 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/service/impl/CwjsPolicyInfoServiceImpl.java

@@ -28,6 +28,16 @@ public class CwjsPolicyInfoServiceImpl extends ServiceImpl<CwjsPolicyInfoMapper,
     @Resource
     CwjsPolicyInfoMapper policyInfoMapper;
 
+    /**
+     *
+     * @description: 查看政策列表
+     *  已通过的政策 按照 产品名称 拆分多条
+     *
+     * @param policyInfo
+     * @return: java.util.List<org.jeecg.ctop.finance.policy.entity.CwjsPolicyInfo>
+     * @author: zianY
+     * @time: 2022/3/29
+     */
     @Override
     public List<CwjsPolicyInfo> queryPageList(CwjsPolicyInfo policyInfo){