浏览代码

Merge branch 'master' of http://47.100.37.243:10191/wutt/manHourHousekeeper

QuYueTing 3 周之前
父节点
当前提交
652d8bf1a3

+ 35 - 34
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/WechatCallbackController.java

@@ -1,8 +1,7 @@
 package com.management.platform.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.management.platform.entity.Custom;
-import com.management.platform.entity.User;
+import com.management.platform.entity.MiniBindUser;
 import com.management.platform.entity.WechatQrcodeScan;
 import com.management.platform.entity.WechatUserFollow;
 import com.management.platform.mapper.WechatQrcodeScanMapper;
@@ -27,7 +26,7 @@ import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.Arrays;
-import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -171,30 +170,34 @@ public class WechatCallbackController {
                 followRecord.setSalesmanId(salesmanId);
                 followMapper.insert(followRecord);
 
-                /*List<MiniBindUser> miniBindUserList = miniBindUserService.list(new QueryWrapper<MiniBindUser>()
-                        .eq("unionid", scanRecord.getUnionid())
-                        .orderByDesc("create_time")
-                        .last("limit 1"));*/
+                log.info("销售人员的id==>"+salesmanId);
+                log.info("用户的openid==>"+openId);
+                List<MiniBindUser> miniBindUserList = miniBindUserService.list(new QueryWrapper<MiniBindUser>()
+                        .eq("openid", scanRecord.getOpenId()).eq("user_id",salesmanId));
+
+                if (miniBindUserList.isEmpty()){
+                    /*int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
+                    if(count==0) {
+                        Custom custom = new Custom();
+                        custom.setCustomName(openId);//用户的openId
+                        custom.setIsDelete(0);
+                        custom.setCreateTime(new Date());
+                        if (StringUtils.isNotEmpty(salesmanId)) {
+                            custom.setInchargerId(salesmanId);
+                            User user = userService.getById(salesmanId);
+                            custom.setCompanyId(user != null ? user.getCompanyId() : null);
+                            customService.save(custom);
+                            log.info("新增客户成功");
+                        }
+                    }else {
+                        log.info("已存在custom_name为"+openId+"的客户");
+                    }*/
+                    MiniBindUser miniBindUser = new MiniBindUser();
+                    miniBindUser.setUserId(salesmanId).setOpenid(openId).setCreateTime(LocalDateTime.now());
+                    miniBindUserService.save(miniBindUser);
+                    log.info("用户关注服务号销售人员的二维码,绑定销售人员和用户id成功");
 
-//                if (!miniBindUserList.isEmpty()){
-                int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
-                if(count==0) {
-                    Custom custom = new Custom();
-                    custom.setCustomName(openId);//用户的openId
-                    custom.setIsDelete(0);
-                    custom.setCreateTime(new Date());
-                    if (StringUtils.isNotEmpty(salesmanId)) {
-                        custom.setInchargerId(salesmanId);
-                        User user = userService.getById(salesmanId);
-                        custom.setCompanyId(user != null ? user.getCompanyId() : null);
-                        customService.save(custom);
-                        log.info("新增客户成功");
-                    }
-                }else {
-                    log.info("已存在custom_name为"+openId+"的客户");
                 }
-//                }
-                log.info("用户关注成功");
             } else {
                 followRecord.setIsFollow(true);
                 followRecord.setFollowTime(LocalDateTime.now());
@@ -204,17 +207,15 @@ public class WechatCallbackController {
             }
         }
     }
-    
+
+    //取消关注
     private void handleUnsubscribe(String openId) {
-        WechatUserFollow followRecord = followMapper.findByOpenId(openId);
-        if (followRecord != null) {
-            followRecord.setIsFollow(false);
-            followRecord.setUnfollowTime(LocalDateTime.now());
-            followMapper.update(followRecord);
 
-            customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
-            log.info("用户取消关注成功");
-        }
+        followMapper.delete(new QueryWrapper<WechatUserFollow>().eq("open_id", openId));
+//      customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
+        miniBindUserService.remove(new QueryWrapper<MiniBindUser>().eq("openid", openId));
+        log.info("用户取消绑定销售人员成功");
+
     }
     
     private String successResponse(Element root) {

+ 6 - 0
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/entity/MiniBindUser.java

@@ -49,6 +49,12 @@ public class MiniBindUser extends Model<MiniBindUser> {
     @TableField("user_id")
     private String userId;
 
+    /**
+     * 用户的openid
+     */
+    @TableField("openid")
+    private String openid;
+
     /**
      * 创建时间
      */

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -290,6 +290,22 @@ public class ProjectController {
         return projectService.getTimeCostByCategory(startDate, endDate, userIds, request);
     }
 
+    /**
+     * 获取工单号对应的工时成本
+     */
+    @RequestMapping("/getTimeCostByWorkNum")
+    public HttpRespMsg getTimeCostByWorkNum(String startDate, String endDate) {
+        return projectService.getTimeCostByWorkNum(startDate, endDate, request);
+    }
+
+    /**
+     * 导出工单号对应的工时成本
+     */
+    @RequestMapping("/exportTimeCostByWorkNum")
+    public HttpRespMsg exportTimeCostByWorkNum(String startDate, String endDate) {
+        return projectService.exportTimeCostByWorkNum(startDate, endDate, request);
+    }
+
     /**
      * 导出查询者所在公司每个项目的工时成本
      */

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ProjectMapper.java

@@ -275,4 +275,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
     List<String> getExistIds(@Param("projectCodes") List<String> projectCodes,@Param("companyId") Integer companyId);
 
     void batchInsert(@Param("toAddList") List<Project> toAddList);
+
+    List<Map<String, Object>> getTimeCostByWorkNum(Integer companyId, String startDate, String endDate);
 }

+ 4 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectService.java

@@ -332,4 +332,8 @@ public interface ProjectService extends IService<Project> {
     HttpRespMsg exportTaskPlanFTEData(String monthStart, String monthEnd, String area, String userId, Integer departmentId, HttpServletRequest request);
 
     HttpRespMsg initTaskGroups(Integer companyId);
+
+    HttpRespMsg getTimeCostByWorkNum(String startDate, String endDate, HttpServletRequest request);
+
+    HttpRespMsg exportTimeCostByWorkNum(String startDate, String endDate, HttpServletRequest request);
 }

+ 72 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -13984,6 +13984,78 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return httpRespMsg;
     }
 
+    @Override
+    public HttpRespMsg getTimeCostByWorkNum(String startDate, String endDate, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        try {
+            User targetUser = userMapper.selectById(request.getHeader("Token"));
+            Integer companyId =targetUser.getCompanyId();
+            Map<String, Object> resultMap = new HashMap<>();
+            List<Map<String, Object>> list = projectMapper.getTimeCostByWorkNum(companyId, startDate, endDate);
+            BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
+            for (Map<String, Object> map : list) {
+                if (!map.containsKey("cost")) {
+                    map.put("cost", 0);
+                }
+                if (!map.containsKey("costMoney")) {
+                    map.put("costMoney", 0);
+                } else {
+                    totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
+                }
+            }
+            resultMap.put("costList", list);
+            resultMap.put("totalMoneyCost", totalMoneyCost);
+
+            httpRespMsg.data = resultMap;
+        } catch (NullPointerException e) {
+            //httpRespMsg.setError("验证失败");
+            httpRespMsg.setError(MessageUtils.message("access.verificationError"));
+            return httpRespMsg;
+        }
+        return httpRespMsg;
+    }
+
+    @Override
+    public HttpRespMsg exportTimeCostByWorkNum(String startDate, String endDate, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        User user = userMapper.selectById(request.getHeader("token"));
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
+        CompanyDingding dingding = companyDingdingMapper.selectOne(new QueryWrapper<CompanyDingding>().eq("company_id", user.getCompanyId()));
+        HttpRespMsg msg = getTimeCostByWorkNum(startDate, endDate, request);
+        Map<String, Object> data = (Map<String, Object>) (Map<String, Object>) msg.data;
+        List<Map<String, Object>> resultList = (List<Map<String, Object>>) data.get("costList");
+
+        List<List<String>> dataList=new ArrayList<>();
+        List<String> titleList=new ArrayList<>();
+
+        titleList.add("序号");
+        titleList.add("工单号");
+        titleList.add("工时");
+        titleList.add("工时成本");
+        dataList.add(titleList);
+        for (int i = 0; i < resultList.size(); i++) {
+            List<String> strList=new ArrayList<>();
+            strList.add(String.valueOf(i+1));
+            Map<String, Object> stringObjectMap = resultList.get(i);
+            strList.add((String) stringObjectMap.get("workNum"));
+            String costStr = String.format("%.2f", (Double)stringObjectMap.get("cost"));
+            BigDecimal costMoney = (BigDecimal) stringObjectMap.get("costMoney");
+            String costMoneyStr = costMoney.setScale(2, RoundingMode.HALF_UP).toString();
+
+            strList.add(costStr);
+            strList.add(costMoneyStr);
+            dataList.add(strList);
+        }
+        String fileName = "工单工时成本统计表"+System.currentTimeMillis();
+        try {
+            return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,dingding,fileName, dataList, path);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        httpRespMsg.data =  pathPrefix + fileName+".xlsx";
+        return httpRespMsg;
+    }
+
     //导出FTE报表数据
     @Override
     public HttpRespMsg exportFTEData(String monthStart,String monthEnd, String area,Integer departmentId,HttpServletRequest request) {

+ 32 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -2985,6 +2985,38 @@
         where company_id = #{companyId}
           and project_code in <foreach collection="projectCodes" item="projectCode" separator="," open="(" close=")">#{projectCode}</foreach>
     </select>
+<!--    <select id="getTimeCostByWorkNum" resultType="java.util.Map">
+        SELECT  SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(b.extra_field4,'无工单') as categoryName
+        FROM report AS b
+        WHERE b.company_id = #{companyId}
+        <if test="startDate != null and endDate != null">
+            AND b.create_date between #{startDate} and #{endDate}
+        </if>
+        AND b.state = 1
+        GROUP BY b.extra_field4
+        ORDER BY b.extra_field4 ASC
+    </select>-->
+    <select id="getTimeCostByWorkNum" resultType="java.util.Map">
+        SELECT
+            SUM(b.working_time) AS cost,
+            SUM(b.cost) AS costMoney,
+        CASE
+            WHEN b.extra_field4 IS NULL OR b.extra_field4 = '' THEN '无工单'
+            ELSE b.extra_field4
+            END AS workNum
+        FROM report AS b
+        WHERE b.company_id = #{companyId}
+        <if test="startDate != null and endDate != null">
+            AND b.create_date between #{startDate} and #{endDate}
+        </if>
+        AND b.state = 1
+        GROUP BY
+        CASE
+            WHEN b.extra_field4 IS NULL OR b.extra_field4 = '' THEN '无工单'
+            ELSE b.extra_field4
+            END
+        ORDER BY workNum ASC
+    </select>
 
 
 </mapper>