dcs 1 год назад
Родитель
Сommit
6831913f36

+ 27 - 20
virgo.api/src/main/java/com/bosshand/virgo/api/controller/PaymentController.java

@@ -8,40 +8,47 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 
 @RestController
 @RequestMapping({"payment"})
-@Api(tags = {"缴费管理"})
+@Api(tags = {"账单缴费管理"})
 public class PaymentController {
 
     @Autowired
     PaymentService paymentService;
 
-    @ApiOperation("保存")
-    @RequestMapping(value = "", method = RequestMethod.POST)
-    public Response insert(@RequestBody Payment payment) {
-        paymentService.insert(payment);
-        return Response.ok();
-    }
+    @ApiOperation("分页获取")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response list(@RequestBody Payment payment, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = paymentService.getTotalCount(payment);
+        List<Payment> dataList = paymentService.getLimit(payment, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
 
-    @ApiOperation("获取")
-    @RequestMapping(value = "/list", method = RequestMethod.POST)
-    public Response getList(@RequestBody Payment payment) {
-        return Response.ok(paymentService.getList(payment));
     }
 
-    @ApiOperation("更新")
-    @RequestMapping(value = "/update", method = RequestMethod.PUT)
-    public Response update(@RequestBody Payment payment) {
-        paymentService.update(payment);
+    @ApiOperation("更新状态")
+    @RequestMapping(value = "/updateStatus/{id}/{status}", method = RequestMethod.PUT)
+    public Response update(@PathVariable long id, @PathVariable Integer status) {
+        paymentService.updateStatus(id, status);
         return Response.ok();
     }
 
-    @ApiOperation("删除")
-    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
-    public Response delete(@PathVariable long id) {
-        paymentService.delete(id);
-        return Response.ok();
+    @ApiOperation("生成账单")
+    @RequestMapping(value = "/generate/{clauseId}", method = RequestMethod.GET)
+    public Response generate(@PathVariable long clauseId) {
+        List<Payment> list = paymentService.getContractId(clauseId);
+        if (list != null) {
+            return Response.fail(200001, "合同下账单已生成好了!");
+        }
+        paymentService.generate(clauseId);
+        return Response.ok("账单已生成!");
     }
 
 }

+ 9 - 3
virgo.api/src/main/java/com/bosshand/virgo/api/dao/PaymentDao.java

@@ -2,18 +2,24 @@ package com.bosshand.virgo.api.dao;
 
 import com.bosshand.virgo.api.model.Payment;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
 @Mapper
 public interface PaymentDao {
 
-    int insert (Payment payment);
-
-    int update(Payment payment);
+    int batchInsert (List<Payment> list);
 
     int delete(long id);
 
     List<Payment> getList(Payment payment);
 
+    int updateStatus(long id, Integer status);
+
+    List<Payment> getContractId(long contractId);
+
+    int getTotalCount(Payment payment);
+
+    List<Payment> getLimit(@Param("p") Payment p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
 }

+ 10 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/Contract.java

@@ -179,6 +179,8 @@ public class Contract {
      */
     private Integer status;
 
+    private List<Integer> statusList;
+
     /**
      * 自定义字段
      */
@@ -469,6 +471,14 @@ public class Contract {
         this.status = status;
     }
 
+    public List<Integer> getStatusList() {
+        return statusList;
+    }
+
+    public void setStatusList(List<Integer> statusList) {
+        this.statusList = statusList;
+    }
+
     public String getData() {
         return data;
     }

+ 157 - 6
virgo.api/src/main/java/com/bosshand/virgo/api/model/Payment.java

@@ -1,13 +1,69 @@
 package com.bosshand.virgo.api.model;
 
+import java.math.BigDecimal;
+
 /**
- * 缴费管理
+ * 账单缴费管理
  */
 public class Payment {
 
     private long id;
 
-    private long projectId;
+    /**
+     * 合同id
+     */
+    private long contractId;
+
+    /**
+     * 收款组织id
+     */
+    private long organizationId;
+
+    private String organizationName;
+
+    /**
+     * 付款企业id
+     */
+    private long payMerchantId;
+
+    private String payMerchantName;
+
+    /**
+     * 付款客户id
+     */
+    private long payClientId;
+
+    private String payClientName;
+
+    /**
+     * 开始日
+     */
+    private String startDate;
+
+    /**
+     * 结束日
+     */
+    private String endDate;
+
+    /**
+     * 期数
+     */
+    private Integer phase;
+
+    /**
+     * 金额
+     */
+    private BigDecimal amount;
+
+    /**
+     * 金额介绍
+     */
+    private String data;
+
+    /**
+     * 状态
+     */
+    private Integer status;
 
     public long getId() {
         return id;
@@ -17,12 +73,107 @@ public class Payment {
         this.id = id;
     }
 
-    public long getProjectId() {
-        return projectId;
+    public long getContractId() {
+        return contractId;
+    }
+
+    public void setContractId(long contractId) {
+        this.contractId = contractId;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public String getOrganizationName() {
+        return organizationName;
+    }
+
+    public void setOrganizationName(String organizationName) {
+        this.organizationName = organizationName;
+    }
+
+    public long getPayMerchantId() {
+        return payMerchantId;
+    }
+
+    public void setPayMerchantId(long payMerchantId) {
+        this.payMerchantId = payMerchantId;
+    }
+
+    public String getPayMerchantName() {
+        return payMerchantName;
+    }
+
+    public void setPayMerchantName(String payMerchantName) {
+        this.payMerchantName = payMerchantName;
+    }
+
+    public long getPayClientId() {
+        return payClientId;
+    }
+
+    public void setPayClientId(long payClientId) {
+        this.payClientId = payClientId;
+    }
+
+    public String getPayClientName() {
+        return payClientName;
+    }
+
+    public void setPayClientName(String payClientName) {
+        this.payClientName = payClientName;
+    }
+
+    public String getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(String startDate) {
+        this.startDate = startDate;
+    }
+
+    public String getEndDate() {
+        return endDate;
     }
 
-    public void setProjectId(long projectId) {
-        this.projectId = projectId;
+    public void setEndDate(String endDate) {
+        this.endDate = endDate;
     }
 
+    public Integer getPhase() {
+        return phase;
+    }
+
+    public void setPhase(Integer phase) {
+        this.phase = phase;
+    }
+
+    public BigDecimal getAmount() {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount) {
+        this.amount = amount;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
 }

+ 120 - 8
virgo.api/src/main/java/com/bosshand/virgo/api/service/PaymentService.java

@@ -1,10 +1,19 @@
 package com.bosshand.virgo.api.service;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.bosshand.virgo.api.dao.ContractDao;
 import com.bosshand.virgo.api.dao.PaymentDao;
+import com.bosshand.virgo.api.model.Clause;
+import com.bosshand.virgo.api.model.Contract;
 import com.bosshand.virgo.api.model.Payment;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+import java.util.LinkedList;
 import java.util.List;
 
 @Service
@@ -13,20 +22,123 @@ public class PaymentService {
     @Autowired
     private PaymentDao paymentDao;
 
-    public int insert (Payment payment){
-        return paymentDao.insert(payment);
-    }
+    @Autowired
+    private ContractDao contractDao;
+
+    public void generate(long clauseId) {
+
+        LinkedList<Payment> list = new LinkedList<>();
+
+        Contract contract = contractDao.get(clauseId);
+        List<Clause> clauseList = contract.getClauseList();
+
+        // 开始时间
+        String start = null;
+        // 结束时间
+        String end = null;
+        // 几月一付
+        long payCycle = 0;
+        // 保证金
+        BigDecimal earnestMoney = null;
+        // 单价租金
+        BigDecimal unitPrice = null;
+
+        JSONArray array = new JSONArray();
+        // 计数
+        int a = 0;
+        for (Clause clause : clauseList) {
+            // 租赁条款
+            if (clause.getType() == 1) {
+                start = clause.getStartTime();
+                end = clause.getEndTime();
+                payCycle = Long.parseLong(clause.getPayCycle());
+                unitPrice = new BigDecimal(clause.getUnitPrice());
+            } else {
+                // 保证金条款
+                JSONObject json = new JSONObject();
+                if (a > 0) {
+                    json.put("earnestMoneyType", clause.getEarnestMoneyType());
+                    json.put("earnestMoney", clause.getEarnestMoney());
+                    array.add(json);
+                    BigDecimal bigDecimal = new BigDecimal(clause.getEarnestMoney());
+                    earnestMoney.add(bigDecimal);
+                } else {
+                    json.put("earnestMoneyType", clause.getEarnestMoneyType());
+                    json.put("earnestMoney", clause.getEarnestMoney());
+                    array.add(json);
+                    earnestMoney = new BigDecimal(clause.getEarnestMoney());
+                    a = a + 1;
+                }
+            }
+        }
+
+        LocalDate startDate = LocalDate.parse(start);
+        LocalDate endDate = LocalDate.parse(end);
 
-    public int update(Payment payment){
-        return paymentDao.update(payment);
+        // 计算期数
+        long monthsDifference = ChronoUnit.MONTHS.between(startDate, endDate);
+        int in = (int) Math.ceil(monthsDifference / payCycle);
+
+        int b = 1;
+        for (int i = 0; i < in; i++) {
+            Payment payment = new Payment();
+            JSONObject json = new JSONObject();
+            if (i == 0) {
+                payment.setStartDate(start);
+                // 计算指定日期后几个月的日期
+                payment.setEndDate(startDate.plusMonths(payCycle).toString());
+                payment.setContractId(clauseId);
+                payment.setPayMerchantId(contract.getMerchantId());
+                payment.setOrganizationId(contract.getOrganizationId());
+                payment.setPayClientId(contract.getClientId());
+                BigDecimal cycle = new BigDecimal(payCycle);
+                payment.setAmount(unitPrice.multiply(cycle).add(earnestMoney));
+                json.put("payCycle",payCycle);
+                json.put("unitPrice", unitPrice);
+                array.add(json);
+                payment.setData(array.toJSONString());
+                payment.setPhase(b + i);
+                list.add(payment);
+                continue;
+            }
+            int c = i - 1;
+            payment.setStartDate(list.get(c).getEndDate());
+            payment.setEndDate(LocalDate.parse(list.get(c).getEndDate()).plusMonths(payCycle).toString());
+            payment.setContractId(clauseId);
+            payment.setPayMerchantId(contract.getMerchantId());
+            payment.setOrganizationId(contract.getOrganizationId());
+            payment.setPayClientId(contract.getClientId());
+            BigDecimal cycle = new BigDecimal(payCycle);
+            payment.setAmount(unitPrice.multiply(cycle));
+            json.put("payCycle",payCycle);
+            json.put("unitPrice", unitPrice);
+            payment.setData(json.toJSONString());
+            payment.setPhase(b + i);
+            list.add(payment);
+        }
+        paymentDao.batchInsert(list);
     }
 
-    public int delete(long id){
-        return paymentDao.delete(id);
+
+    public int updateStatus(long id, Integer status) {
+        return paymentDao.updateStatus(id, status);
     }
 
-    public List<Payment> getList(Payment payment){
+    public List<Payment> getList(Payment payment) {
         return paymentDao.getList(payment);
     }
 
+    public List<Payment> getContractId(long contractId) {
+        return paymentDao.getContractId(contractId);
+    }
+
+    public int getTotalCount(Payment payment) {
+        return paymentDao.getTotalCount(payment);
+    }
+
+    public List<Payment> getLimit(Payment payment, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return paymentDao.getLimit(payment, currIndex, pageSize);
+    }
+
 }

+ 10 - 0
virgo.api/src/main/resources/mapper/ContractMapper.xml

@@ -242,6 +242,11 @@
             <if test="attachment!=null">and attachment=#{attachment}</if>
             <if test="document!=null">and document=#{document}</if>
             <if test="status!=null">and status=#{status}</if>
+            <if test="statusList!=null"> and status in
+                <foreach item="item" index="index" collection="statusList" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
             <if test="data!=null">and data=#{data}</if>
         </where>
     </select>
@@ -283,6 +288,11 @@
             <if test="p.attachment!=null">and attachment=#{p.attachment}</if>
             <if test="p.document!=null">and document=#{p.document}</if>
             <if test="p.status!=null">and status=#{p.status}</if>
+            <if test="p.statusList!=null"> and status in
+                <foreach item="item" index="index" collection="p.statusList" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
             <if test="p.data!=null">and data=#{p.data}</if>
         </where>
         limit #{currIndex} , #{pageSize}

+ 3 - 3
virgo.api/src/main/resources/mapper/MerchantMapper.xml

@@ -51,7 +51,7 @@
         <where>
             <if test="organizationId!=0">and organizationId=#{organizationId}</if>
             <if test="industryType!=null">and industryType=#{industryType}</if>
-            <if test="name!=null">and name=#{name},</if>
+            <if test="name!=null">and name=#{name}</if>
             <if test="legalPerson!=null">and legalPerson=#{legalPerson}</if>
             <if test="establishDate!=null">and establishDate=#{establishDate}</if>
             <if test="businessTerm!=null">and businessTerm=#{businessTerm}</if>
@@ -66,7 +66,7 @@
         <where>
             <if test="organizationId!=0">and organizationId=#{organizationId}</if>
             <if test="industryType!=null">and industryType=#{industryType}</if>
-            <if test="name!=null">and name=#{name},</if>
+            <if test="name!=null">and name=#{name}</if>
             <if test="legalPerson!=null">and legalPerson=#{legalPerson}</if>
             <if test="establishDate!=null">and establishDate=#{establishDate}</if>
             <if test="businessTerm!=null">and businessTerm=#{businessTerm}</if>
@@ -81,7 +81,7 @@
         <where>
             <if test="p.organizationId!=0">and organizationId=#{p.organizationId}</if>
             <if test="p.industryType!=null">and industryType=#{p.industryType}</if>
-            <if test="p.name!=null">and name=#{p.name},</if>
+            <if test="p.name!=null">and name=#{p.name}</if>
             <if test="p.legalPerson!=null">and legalPerson=#{p.legalPerson}</if>
             <if test="p.establishDate!=null">and establishDate=#{p.establishDate}</if>
             <if test="p.businessTerm!=null">and businessTerm=#{p.businessTerm}</if>

+ 107 - 9
virgo.api/src/main/resources/mapper/PaymentMapper.xml

@@ -6,35 +6,133 @@
 
     <resultMap type="com.bosshand.virgo.api.model.Payment" id="paymentResult">
         <id column="id" property="id"/>
-        <result column="projectId" property="projectId"/>
+        <result column="contractId" property="contractId"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="organizationName" property="organizationName"/>
+        <result column="payMerchantId" property="payMerchantId"/>
+        <result column="payMerchantName" property="payMerchantName"/>
+        <result column="payClientId" property="payClientId"/>
+        <result column="payClientName" property="payClientName"/>
+        <result column="startDate" property="startDate"/>
+        <result column="endDate" property="endDate"/>
+        <result column="phase" property="phase"/>
+        <result column="amount" property="amount"/>
+        <result column="status" property="status"/>
+        <result column="data" property="data"/>
     </resultMap>
 
-    <insert id="insert" parameterType="com.bosshand.virgo.api.model.Payment" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO payment(projectId) VALUES (#{projectId})
+    <insert id="batchInsert" parameterType="com.bosshand.virgo.api.model.Payment" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO payment(`contractId`, `organizationId`, `payMerchantId`, `payClientId`, `startDate`, `endDate`, `phase`, `amount`, `status`, `data`)
+        VALUES
+        <foreach collection="list" item="item" index="index" separator=",">
+               (#{item.contractId}, #{item.organizationId}, #{item.payMerchantId}, #{item.payClientId}, #{item.startDate}, #{item.endDate}, #{item.phase}, #{item.amount}, #{item.status}, #{item.data})
+        </foreach>
     </insert>
 
     <delete id="delete">
         DELETE from payment where id=#{id}
     </delete>
 
-    <update id="update" parameterType="com.bosshand.virgo.api.model.Payment">
+    <update id="updateStatus" parameterType="com.bosshand.virgo.api.model.Payment">
         UPDATE payment
         <trim prefix="set" suffixOverrides=",">
-            <if test="projectId!=0">projectId=#{projectId},</if>
+            <if test="status!=null">status=#{status},</if>
         </trim>
         WHERE id=#{id}
     </update>
 
+    <select id="getContractId" resultMap="paymentResult">
+        SELECT contractId FROM payment where contractId = #{contractId}
+    </select>
+
     <select id="getList" resultMap="paymentResult">
         SELECT * FROM payment
         <where>
-            <if test="id != 0">
-                and id = #{id}
+            <if test="contractId != 0">
+                and contractId = #{contractId}
+            </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="payMerchantId != 0">
+                and payMerchantId = #{payMerchantId}
             </if>
-            <if test="projectId != 0">
-                and projectId = #{projectId}
+            <if test="payClientId != 0">
+                and payClientId = #{payClientId}
+            </if>
+            <if test="startDate != null">
+                and startDate = #{startDate}
+            </if>
+            <if test="endDate != null">
+                and endDate = #{endDate}
+            </if>
+            <if test="status != null">
+                and status = #{status}
             </if>
         </where>
     </select>
 
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Payment" resultType="Integer">
+        SELECT count(*) FROM payment
+        <where>
+            <if test="contractId != 0">
+                and contractId = #{contractId}
+            </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="payMerchantId != 0">
+                and payMerchantId = #{payMerchantId}
+            </if>
+            <if test="payClientId != 0">
+                and payClientId = #{payClientId}
+            </if>
+            <if test="startDate != null">
+                and startDate = #{startDate}
+            </if>
+            <if test="endDate != null">
+                and endDate = #{endDate}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+        </where>
+    </select>
+
+    <sql id="query">
+        SELECT a.*, b.name as organizationName, c.name as payMerchantName, d.name as payClientName FROM payment a
+        LEFT JOIN mgr_organization b ON a.organizationId = b.id
+        LEFT JOIN merchant c ON a.payMerchantId = c.id
+        LEFT JOIN mgr_client d ON a.payClientId = d.id
+    </sql>
+
+    <select id="getLimit" resultMap="paymentResult">
+        <include refid="query"/>
+        <where>
+            <if test="p.contractId != 0">
+                and a.contractId = #{p.contractId}
+            </if>
+            <if test="p.organizationId != 0">
+                and a.organizationId = #{p.organizationId}
+            </if>
+            <if test="p.payMerchantId != 0">
+                and a.payMerchantId = #{p.payMerchantId}
+            </if>
+            <if test="p.payClientId != 0">
+                and a.payClientId = #{p.payClientId}
+            </if>
+            <if test="p.startDate != null">
+                and a.startDate = #{p.startDate}
+            </if>
+            <if test="p.endDate != null">
+                and a.endDate = #{p.endDate}
+            </if>
+            <if test="p.status != null">
+                and a.status = #{p.status}
+            </if>
+        </where>
+        limit #{currIndex} , #{pageSize}
+    </select>
+
+
 </mapper>

+ 1 - 1
virgo.core/src/main/java/com/bosshand/virgo/core/utils/DateTimeUtils.java

@@ -251,7 +251,7 @@ public class DateTimeUtils {
         return false;
     }
 
-    /*
+    /**
      * 设置有效时间至次日00:05:00
      */
     public static long getTodayExpireTime() {