Sfoglia il codice sorgente

同步开票数据修改&绩效分配接口查询优化

wucl 6 mesi fa
parent
commit
a630ae977c

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

@@ -1,5 +1,6 @@
 package com.dayou.controller;
 
+import com.dayou.annotation.DataPermission;
 import com.dayou.dto.CommonCheckDTO;
 import com.dayou.dto.TaskRecordDTO;
 import com.dayou.dto.WareHouseDTO;
@@ -341,9 +342,10 @@ public class MajorProductionController extends BaseController {
      * @param productionPerformance
      * @return
      */
+    @DataPermission(department = true, postChild = false)
     @GetMapping("/performance/allot")
-    public RestResponse<Page<MajorProductionPerformanceVO>> performanceAllotPage(Page page ,MajorProductionPerformanceVO productionPerformance){
-        Page<MajorProductionPerformanceVO> ret = majorProductionService.performanceAllotPage(page,productionPerformance);
+    public RestResponse<Page<MajorProductionPerformanceVO>> performanceAllotPage(MajorProductionPerformanceVO productionPerformance,Page page,String keyword){
+        Page<MajorProductionPerformanceVO> ret = majorProductionService.performanceAllotPage(page,productionPerformance,keyword);
         return RestResponse.data(ret);
     }
 }

+ 1 - 1
dao/src/main/java/com/dayou/mapper/DyoaHistoryMapper.java

@@ -45,7 +45,7 @@ public interface DyoaHistoryMapper {
 
     List<HisAssetsProduction> queryAssetsProduction(@Param("id") String id);
 
-    List<String> getNewFinanceInvoice(@Param("max") Date max);
+    List<String> getNewFinanceInvoice();
 
     Map<String, Object> getInvoiceInfo(@Param("id") String id);
 

+ 3 - 0
dao/src/main/java/com/dayou/mapper/DyoaRecordMapper.java

@@ -3,6 +3,7 @@ package com.dayou.mapper;
 import com.dayou.dto.history.HisPersonalProduction;
 import com.dayou.entity.DyoaRecord;
 import com.dayou.dao.CustomBaseMapper;
+import com.dayou.entity.FinanceInvoice;
 import com.dayou.entity.OrderFund;
 import org.apache.ibatis.annotations.Param;
 
@@ -43,4 +44,6 @@ public interface DyoaRecordMapper extends CustomBaseMapper<DyoaRecord> {
     List<HisPersonalProduction> findAssetsProduction();
 
     Long getPersonalTargetId(@Param("id")String id);
+
+    FinanceInvoice getMbsIdByDyOAiDForInvoice(@Param("dyoaId") String dyoaId);
 }

+ 1 - 1
dao/src/main/java/com/dayou/mapper/MajorProductionMapper.java

@@ -46,7 +46,7 @@ public interface MajorProductionMapper extends CustomBaseMapper<MajorProduction>
 
     void updateSaveFileInfo(@Param("productionIds") List<Long> productionIds);
 
-    Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, @Param("vo") MajorProductionPerformanceVO vo,@Param("currentUserId") Long currentUserId);
+    Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, @Param("vo") MajorProductionPerformanceVO vo,@Param("keyword") String keyword);
 
     ProdValidateVO validateProd(@Param("id") Long id);
 

+ 2 - 6
dao/src/main/resources/mapper/DyoaHistoryMapper.xml

@@ -361,16 +361,12 @@
             da.deleted = 0 and da.id = #{id}
     </select>
 
-    <select id="getNewFinanceInvoice" parameterType="java.util.Date" resultType="java.lang.String">
+    <select id="getNewFinanceInvoice"  resultType="java.lang.String">
         SELECT
         id
         FROM
         dy_finance_invoice
-        <where>
-            <if test="max!=null">
-                and createdDatetime &gt; #{max}
-            </if>
-        </where>
+
     </select>
 
     <select id="getInvoiceInfo" parameterType="java.lang.String" resultType="map">

+ 16 - 0
dao/src/main/resources/mapper/DyoaRecordMapper.xml

@@ -89,4 +89,20 @@
             deleted = 0
     </select>
 
+    <select id="getMbsIdByDyOAiDForInvoice" parameterType="java.lang.String" resultType="com.dayou.entity.FinanceInvoice">
+        SELECT
+            *
+        FROM
+            finance_invoice
+        WHERE
+            id = (
+                SELECT
+                    mbs_id
+                FROM
+                    dyoa_record
+                WHERE
+                    dyoa_id = #{dyoaId}
+                  AND mbs_type = 'FINANCE_INVOICE')
+    </select>
+
 </mapper>

+ 4 - 2
dao/src/main/resources/mapper/FinanceRealFundMapper.xml

@@ -279,7 +279,8 @@
         mp.*
         FROM
         ( SELECT business_id, production_no,
-        ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production
+        ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
+        production_type
         , production_should_amount, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS'
         AND deleted = 0 and production_should_amount is not null and production_should_amount!=0  and real_amount is null)  pf
         inner join
@@ -288,6 +289,7 @@
         id,
         major_id,
         report_no,
+        production as productionType,
         NAME,
         evaluate_amount,
         repertory_out_time,
@@ -298,7 +300,7 @@
         deleted = 0
         AND repertory_out_time IS NOT NULL
         ) mp
-        ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no )
+        ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no and mp.productionType = pf.production_type )
 
         LEFT JOIN major m ON m.id = mp.major_id
         LEFT JOIN user u ON u.id = m.client_manager_id

+ 27 - 16
dao/src/main/resources/mapper/MajorProductionMapper.xml

@@ -628,25 +628,35 @@
 
     <select id="performanceAllotPage" parameterType="com.dayou.vo.MajorProductionPerformanceVO" resultType="com.dayou.vo.MajorProductionPerformanceVO">
         SELECT
-            mp.id,
-            m.order_id,
-            m.id as majorId,
-            mp.NAME,
-            mp.report_no,
-            (case mp.production when 'REPORT' then '报告' when 'STATEMENT' THEN '价值意见书' else '复评函' end ) as production,
-            ( SELECT count(id) FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND business_id = m.id AND production_no = mp.report_no AND deleted = 0 ) AS claimTimes,
-            allot.major_production_id AS isAllot
-#             ( SELECT major_production_id FROM major_production_allot WHERE deleted = 0 and user_type = 'EVALUATE' GROUP BY major_production_id HAVING major_production_id = mp.id ) AS isAllot
+        mp.id,
+        m.order_id,
+        m.id as majorId,
+        mp.NAME,
+        mp.report_no,
+        (case mp.production when 'REPORT' then '报告' when 'STATEMENT' THEN '价值意见书' else '复评函' end ) as production,
+        pf.real_amount AS claimAmount,
+        allot.major_production_id AS isAllot
         FROM
-            major_production mp
+        major_production mp
+        left join (select business_id,production_no,production_type,real_amount from production_fund where business_type = 'MAJOR_BUSINESS' and deleted = 0 ) pf on (mp.major_id = pf.business_id and mp.report_no = pf.production_no and mp.production = pf.production_type)
         LEFT JOIN major m ON m.id = mp.major_id
-        left join (select * from production_fund where business_type = 'MAJOR_BUSINESS' and deleted = 0) pf on (pf.business_id = m.id and pf.production_no = mp.report_no and mp.production = pf.production_type)
         LEFT JOIN (SELECT major_production_id FROM major_production_allot WHERE deleted = 0 and user_type = 'EVALUATE' GROUP BY major_production_id) AS allot ON major_production_id = mp.id
         WHERE
-            m.deleted = 0
-          AND mp.deleted = 0
-          AND mp.NAME IS NOT NULL
-          and m.department_id in (select distinct department_id from post where name='评估部经理' and  id in (select post_id from user_post where user_id = #{currentUserId}))
+        m.deleted = 0
+        AND mp.deleted = 0
+        AND mp.NAME IS NOT NULL
+          and m.department_id in (
+        <foreach collection="vo.departmentIds" open="(" close=")" separator="," item="departmentId">
+            #{departmentId}
+        </foreach>
+        )
+        <if test="keyword!=null and keyword!='' ">
+            and (
+            mp.name like concat('%',#{keyword},'%')
+            or m.order_id like concat('%',#{keyword},'%')
+            or mp.report_no like concat('%',#{keyword},'%')
+            )
+        </if>
         <if test="vo!=null and vo.production != null">
             AND mp.production = #{vo.production}
         </if>
@@ -662,7 +672,8 @@
         <if test="vo!=null and vo.hasAllot == false">
             AND allot.major_production_id IS NULL
         </if>
-        order by claimTimes DESC, isAllot ASC
+
+        order by mp.id DESC, isAllot ASC
     </select>
 
     <select id="validateProd" parameterType="java.lang.Long" resultType="com.dayou.vo.ProdValidateVO">

+ 9 - 1
domain/src/main/java/com/dayou/vo/MajorProductionPerformanceVO.java

@@ -2,6 +2,10 @@ package com.dayou.vo;
 
 import lombok.Data;
 
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Set;
+
 /**
  * 类说明:
  *
@@ -24,7 +28,7 @@ public class MajorProductionPerformanceVO {
 
     private String production;
 
-    private Integer claimTimes;
+    private BigDecimal claimAmount;
 
     private Long isAllot;
 
@@ -32,5 +36,9 @@ public class MajorProductionPerformanceVO {
 
     private Boolean hasAllot;
 
+    private List<Long> departmentIds;
+
+    private Set<Long> userIds;
+
 
 }

+ 76 - 56
service/src/main/java/com/dayou/dyoa/DyoaHistoryServiceImpl.java

@@ -49,6 +49,7 @@ import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 import static com.dayou.common.Constants.*;
+import static com.dayou.enums.FinanceInvoiceState.已作废;
 import static com.dayou.enums.MainBusinessEnum.*;
 import static com.dayou.enums.ProductionEnum.FINAL;
 
@@ -626,8 +627,7 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
     @DSTransactional
     @Override
     public void fetchFinanceInvoiceRecord(){
-        Date max = dyoaRecordService.getMaxFinanceInvoiceCreatedTime();
-        List<String> newInvoice = dyoaHistoryMapper.getNewFinanceInvoice(max);
+        List<String> newInvoice = dyoaHistoryMapper.getNewFinanceInvoice();
         newInvoice.stream().forEach(x-> {
             fetchFinanceInvoiceDetail(x);
         });
@@ -636,66 +636,85 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
     private void fetchFinanceInvoiceDetail(String id) {
         try{
             Map<String,Object> resultMap = dyoaHistoryMapper.getInvoiceInfo(id);
-            FinanceInvoice invoice = new FinanceInvoice();
-            Class<FinanceInvoice> fClass = FinanceInvoice.class;
             String dyoaId = (String) resultMap.get("id");
-            for (Map.Entry<String, String> entry : FINANCE_INVOICE_COLUM.entrySet()){
-                Object columValue = resultMap.get(entry.getKey());
-                if (columValue!=null){
-                    String mbsColum = entry.getValue();
-                    Field field = fClass.getDeclaredField(mbsColum);
-                    field.setAccessible(true);
-                    switch (mbsColum){
-                        case "orderFundId":
-                            Long orderFundMbsId = findOrderFundId((String) columValue);
-                            if (orderFundMbsId==null){
-                                return;
-                            }
-                            field.set(invoice, orderFundMbsId);
-                            break;
-                        case "realFundId":
-                            Long realFundId = findRealAmountMbsId((String) columValue);
-                            if (realFundId==null){
-                                return;
-                            }
-                            field.set(invoice, realFundId);
-                            break;
-                        case "planAmount":
-                        case "realAmount":
-                        case "taxAmount":
-                        case "taxRate":
-                            field.set(invoice,BigDecimal.valueOf((Double) columValue));
-                            break;
-                        case "planMakeDate":
-                        case "realMakeDate":
-                            Timestamp ts = (Timestamp) columValue;
-                            field.set(invoice, DateUtils.dateToLocalDate(new Date(ts.getTime())));
-                            break;
-                        case "makerId":
-                            field.set(invoice,getMbsUserId((String) columValue));
-                            break;
-                        case "applyId":
-                            field.set(invoice,getMbsUserId((String) columValue));
-                            break;
-                        default:
-                            field.set(invoice,columValue);
+            FinanceInvoice invoice = dyoaRecordService.getMbsIdByDyOAiDForInvoice(dyoaId);
+            if (invoice==null){
+                invoice = new FinanceInvoice();
+                Class<FinanceInvoice> fClass = FinanceInvoice.class;
+                for (Map.Entry<String, String> entry : FINANCE_INVOICE_COLUM.entrySet()){
+                    Object columValue = resultMap.get(entry.getKey());
+                    if (columValue!=null){
+                        String mbsColum = entry.getValue();
+                        Field field = fClass.getDeclaredField(mbsColum);
+                        field.setAccessible(true);
+                        switch (mbsColum){
+                            case "orderFundId":
+                                Long orderFundMbsId = findOrderFundId((String) columValue);
+                                if (orderFundMbsId==null){
+                                    return;
+                                }
+                                field.set(invoice, orderFundMbsId);
+                                break;
+                            case "realFundId":
+                                Long realFundId = findRealAmountMbsId((String) columValue);
+                                if (realFundId==null){
+                                    return;
+                                }
+                                field.set(invoice, realFundId);
+                                break;
+                            case "planAmount":
+                            case "realAmount":
+                            case "taxAmount":
+                            case "taxRate":
+                                field.set(invoice,BigDecimal.valueOf((Double) columValue));
+                                break;
+                            case "planMakeDate":
+                            case "realMakeDate":
+                                Timestamp ts = (Timestamp) columValue;
+                                field.set(invoice, DateUtils.dateToLocalDate(new Date(ts.getTime())));
+                                break;
+                            case "makerId":
+                                field.set(invoice,getMbsUserId((String) columValue));
+                                break;
+                            case "applyId":
+                                field.set(invoice,getMbsUserId((String) columValue));
+                                break;
+                            default:
+                                field.set(invoice,columValue);
+                        }
+
                     }
 
                 }
-
+                String orderId = (String) resultMap.get("orderId");
+                Long orderFundMbsId = findOrderFundId((String) orderId);
+                Long productionFunId = getProductionFundIdByOrderFundId(orderFundMbsId);
+                invoice.setProductionFundId(productionFunId);
+                Date createdDatetime = (Date) resultMap.get("createdDatetime");
+                invoice.setCreated(createdDatetime);
+                financeInvoiceService.save(invoice);
+                //插入同步记录表
+                Long mbsId = invoice.getId();
+                dyoaRecordService.insert(MainBusinessEnum.FINANCE_INVOICE, mbsId, dyoaId,createdDatetime);
+            }else{
+                String status = (String) resultMap.get("status");
+                if (StrUtil.isNotBlank(status) && "已作废".equals(status)){
+                    invoice.setState("已作废");
+                    invoice.setReason((String) resultMap.get("reason"));
+                    financeInvoiceService.update(invoice);
+                }
+                String state = invoice.getState();
+                if (StrUtil.isNotBlank(state) && "待开票".equals(state) && StrUtil.isNotBlank(status) && "已开票".equals(status)){
+                    invoice.setState("已开票");
+                    Timestamp ts = (Timestamp) resultMap.get("realDate");
+                    invoice.setRealMakeDate(DateUtils.dateToLocalDate(new Date(ts.getTime())));
+                    invoice.setRealAmount(BigDecimal.valueOf((Double) resultMap.get("realMoney")));
+                    invoice.setTicketNo((String) resultMap.get("ticketNo"));
+                    invoice.setMakerId(getMbsUserId((String) resultMap.get("invoiceEmp")));
+                    financeInvoiceService.update(invoice);
+                }
             }
 
-            String orderId = (String) resultMap.get("orderId");
-            Long orderFundMbsId = findOrderFundId((String) orderId);
-            Long productionFunId = getProductionFundIdByOrderFundId(orderFundMbsId);
-            invoice.setProductionFundId(productionFunId);
-
-            Date createdDatetime = (Date) resultMap.get("createdDatetime");
-            invoice.setCreated(createdDatetime);
-            financeInvoiceService.save(invoice);
-            //插入同步记录表
-            Long mbsId = invoice.getId();
-            dyoaRecordService.insert(MainBusinessEnum.FINANCE_INVOICE, mbsId, dyoaId,createdDatetime);
         }catch (NoSuchFieldException e) {
             throw new RuntimeException(e);
         } catch (IllegalAccessException e) {
@@ -1845,6 +1864,7 @@ public class DyoaHistoryServiceImpl implements IDyoaHistoryService{
     }
 
 
+
     @Override
     public Boolean updateProductionFund() {
         List<OrderFund> orderFunds = orderFundService.getAllOrderFund();

+ 1 - 0
service/src/main/java/com/dayou/dyoa/IDyoaHistoryService.java

@@ -47,4 +47,5 @@ public interface IDyoaHistoryService {
     Boolean updatePersonalProduction();
 
     Boolean updateAssetsProduction();
+
 }

+ 1 - 0
service/src/main/java/com/dayou/dyoa/task/FetchDyoaDataSchedule.java

@@ -57,6 +57,7 @@ public class FetchDyoaDataSchedule {
         log.info("同步财务开票数据完成");
     }
 
+
     //每天凌晨06:30触发
     @Scheduled(cron = "0 30 6 * * ?")
     public void updateMajorProduction(){

+ 3 - 0
service/src/main/java/com/dayou/service/IDyoaRecordService.java

@@ -3,6 +3,7 @@ import com.dayou.entity.DyoaRecord;
 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.entity.FinanceInvoice;
 import com.dayou.enums.MainBusinessEnum;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
@@ -46,5 +47,7 @@ public interface IDyoaRecordService extends IService<DyoaRecord> {
     Long getPersonalTargetId(String id);
 
     Long getMbsIdByDyOAIdForAssets(String id);
+
+    FinanceInvoice getMbsIdByDyOAiDForInvoice(String dyoaId);
 }
 

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

@@ -81,7 +81,7 @@ public interface IMajorProductionService extends IService<MajorProduction> {
 
     Boolean doAllotRealAmountToProduction(OrderReportDTO orderReportDTO);
 
-    Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, MajorProductionPerformanceVO productionPerformance);
+    Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, MajorProductionPerformanceVO productionPerformance,String keyword);
 
     Page<MajorProductionVO> waitingClaimProd(Page page, MajorProductionVO production);
 

+ 6 - 0
service/src/main/java/com/dayou/service/impl/DyoaRecordServiceImpl.java

@@ -3,6 +3,7 @@ package com.dayou.service.impl;
 import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.dayou.entity.DyoaRecord;
+import com.dayou.entity.FinanceInvoice;
 import com.dayou.enums.MainBusinessEnum;
 import com.dayou.exception.ErrorCode;
 import com.dayou.mapper.DyoaRecordMapper;
@@ -108,5 +109,10 @@ public class DyoaRecordServiceImpl extends ServiceImpl<DyoaRecordMapper, DyoaRec
         return dyoaRecordMapper.getMbsIdByDyOAIdForAssets(id);
     }
 
+    @Override
+    public FinanceInvoice getMbsIdByDyOAiDForInvoice(String dyoaId) {
+        return dyoaRecordMapper.getMbsIdByDyOAiDForInvoice(dyoaId);
+    }
+
 
 }

+ 2 - 2
service/src/main/java/com/dayou/service/impl/MajorProductionServiceImpl.java

@@ -645,8 +645,8 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
 
 
     @Override
-    public Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, MajorProductionPerformanceVO productionPerformance) {
-        Page<MajorProductionPerformanceVO> result = majorProductionMapper.performanceAllotPage(page,productionPerformance,LoginContext.getCurrentUserId());
+    public Page<MajorProductionPerformanceVO> performanceAllotPage(Page page, MajorProductionPerformanceVO productionPerformance,String keyword) {
+        Page<MajorProductionPerformanceVO> result = majorProductionMapper.performanceAllotPage(page,productionPerformance, keyword);
         return result;
     }