dcs 2 months ago
parent
commit
971d18b3d0

+ 29 - 2
virgo.api/src/main/java/com/bosshand/virgo/api/workark/controller/InvoiceController.java

@@ -1,6 +1,7 @@
 package com.bosshand.virgo.api.workark.controller;
 
 import com.bosshand.virgo.api.workark.model.Invoice;
+import com.bosshand.virgo.api.workark.model.InvoiceModel;
 import com.bosshand.virgo.api.workark.service.InvoiceService;
 import com.bosshand.virgo.core.response.Response;
 import io.swagger.annotations.Api;
@@ -20,11 +21,37 @@ public class InvoiceController {
     @Autowired
     InvoiceService invoiceService;
 
+    @ApiOperation("保存抬头")
+    @RequestMapping(value = "/model", method = RequestMethod.POST)
+    public Response insertModel(@RequestBody InvoiceModel invoiceModel) {
+        invoiceService.saveModel(invoiceModel);
+        return Response.ok();
+    }
+
+    @ApiOperation("更新抬头")
+    @RequestMapping(value = "/model/update", method = RequestMethod.PUT)
+    public Response updateModel(@RequestBody InvoiceModel invoiceModel) {
+        invoiceService.updateModel(invoiceModel);
+        return Response.ok();
+    }
+
+    @ApiOperation("删除抬头")
+    @RequestMapping(value = "/model/delete/{id}", method = RequestMethod.DELETE)
+    public Response deleteModel(@PathVariable long id) {
+        invoiceService.deleteModel(id);
+        return Response.ok();
+    }
+
+    @ApiOperation("查询抬头")
+    @RequestMapping(value = "/model/query", method = RequestMethod.POST)
+    public Response getListModel(@RequestBody InvoiceModel invoiceModel) {
+        return Response.ok(invoiceService.getListModel(invoiceModel));
+    }
+
     @ApiOperation("保存")
     @RequestMapping(value = "", method = RequestMethod.POST)
     public Response insert(@RequestBody Invoice invoice) {
-        invoiceService.save(invoice);
-        return Response.ok();
+        return Response.ok(invoiceService.save(invoice));
     }
 
     @ApiOperation("更新")

+ 1 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/InvoiceDao.java

@@ -23,4 +23,5 @@ public interface InvoiceDao {
 
     List<Invoice> getLimit(@Param("p") Invoice p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
 
+    Invoice getOrderNo(String orderNo);
 }

+ 21 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/dao/InvoiceModelDao.java

@@ -0,0 +1,21 @@
+package com.bosshand.virgo.api.workark.dao;
+
+import com.bosshand.virgo.api.workark.model.InvoiceModel;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface InvoiceModelDao {
+
+    void delete(long id);
+
+    void save(InvoiceModel invoiceModel);
+
+    void update(InvoiceModel invoiceModel);
+
+    List<InvoiceModel> getList(InvoiceModel invoiceModel);
+
+    InvoiceModel get(long id);
+
+}

+ 38 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/Invoice.java

@@ -12,6 +12,20 @@ public class Invoice {
 
     private long id;
 
+    /**
+     * 发票抬头Id
+     */
+    private long invoiceModelId;
+
+    /**
+     * 组织id
+     */
+    private long organizationId;
+    /**
+     * 用户id
+     */
+    private long userId;
+
     /**
      * 创建时间
      */
@@ -81,6 +95,30 @@ public class Invoice {
         this.id = id;
     }
 
+    public long getInvoiceModelId() {
+        return invoiceModelId;
+    }
+
+    public void setInvoiceModelId(long invoiceModelId) {
+        this.invoiceModelId = invoiceModelId;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
     public Date getCreateTime() {
         return createTime;
     }

+ 138 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/workark/model/InvoiceModel.java

@@ -0,0 +1,138 @@
+package com.bosshand.virgo.api.workark.model;
+
+/**
+ * 发票抬头
+ */
+public class InvoiceModel {
+
+    private long id;
+
+    /**
+     * 组织id
+     */
+    private long organizationId;
+    /**
+     * 用户id
+     */
+    private long userId;
+    /**
+     * 发票类型
+     */
+    private String type;
+    /**
+     * 单位名称
+     */
+    private String name;
+    /**
+     * 纳税人识别号
+     */
+    private String taxpayerIdentificationNumber;
+    /**
+     * 注册地址
+     */
+    private String address;
+    /**
+     * 注册电话
+     */
+    private String phone;
+    /**
+     * 开户银行
+     */
+    private String bankAccount;
+    /**
+     * 银行账号
+     */
+    private String bankAccountNumber;
+    /**
+     * 发票内容
+     */
+    private String content;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getTaxpayerIdentificationNumber() {
+        return taxpayerIdentificationNumber;
+    }
+
+    public void setTaxpayerIdentificationNumber(String taxpayerIdentificationNumber) {
+        this.taxpayerIdentificationNumber = taxpayerIdentificationNumber;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getBankAccount() {
+        return bankAccount;
+    }
+
+    public void setBankAccount(String bankAccount) {
+        this.bankAccount = bankAccount;
+    }
+
+    public String getBankAccountNumber() {
+        return bankAccountNumber;
+    }
+
+    public void setBankAccountNumber(String bankAccountNumber) {
+        this.bankAccountNumber = bankAccountNumber;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

+ 51 - 2
virgo.api/src/main/java/com/bosshand/virgo/api/workark/service/InvoiceService.java

@@ -1,7 +1,12 @@
 package com.bosshand.virgo.api.workark.service;
 
 import com.bosshand.virgo.api.workark.dao.InvoiceDao;
+import com.bosshand.virgo.api.workark.dao.InvoiceModelDao;
+import com.bosshand.virgo.api.workark.dao.OrderInfoDao;
 import com.bosshand.virgo.api.workark.model.Invoice;
+import com.bosshand.virgo.api.workark.model.InvoiceModel;
+import com.bosshand.virgo.api.workark.model.OrderInfo;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -13,12 +18,56 @@ public class InvoiceService {
     @Autowired
     InvoiceDao invoiceDao;
 
+    @Autowired
+    InvoiceModelDao invoiceModelDao;
+
+    @Autowired
+    OrderInfoDao orderInfoDao;
+
+    public void deleteModel(long id) {
+        invoiceModelDao.delete(id);
+    }
+
+    public void saveModel(InvoiceModel invoiceModel){
+        invoiceModelDao.save(invoiceModel);
+    }
+
+    public void updateModel(InvoiceModel invoiceModel) {
+        invoiceModelDao.update(invoiceModel);
+    }
+
+    public List<InvoiceModel> getListModel(InvoiceModel invoiceModel){
+        return invoiceModelDao.getList(invoiceModel);
+    }
+
+    public InvoiceModel getModel(long id){
+        return invoiceModelDao.get(id);
+    }
+
     public void delete(long id) {
         invoiceDao.delete(id);
     }
 
-    public void save(Invoice invoice){
-        invoiceDao.save(invoice);
+    public Invoice save(Invoice invoice) {
+
+        // 发票抬头
+        long invoiceModelId = invoice.getInvoiceModelId();
+
+        String orderNo = invoice.getOrderNo();
+        Invoice od = invoiceDao.getOrderNo(orderNo);
+        if (od != null) {
+            return od;
+        }
+
+        InvoiceModel invoiceModel = invoiceModelDao.get(invoiceModelId);
+        Invoice invoice1 = new Invoice();
+        BeanUtils.copyProperties(invoiceModel, invoice1);
+        invoice1.setInvoiceModelId(invoiceModelId);
+        OrderInfo o = orderInfoDao.getOrderNo(orderNo);
+        invoice1.setAmount(o.getTotalFee());
+        invoice1.setOrderNo(invoice.getOrderNo());
+        invoiceDao.save(invoice1);
+        return invoice1;
     }
 
     public void update(Invoice invoice) {

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

@@ -6,9 +6,12 @@
 
     <resultMap type="com.bosshand.virgo.api.workark.model.Invoice" id="result">
         <id column="id" property="id"/>
+        <result column="invoiceModelId" property="invoiceModelId"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="userId" property="userId"/>
         <result column="createTime" property="createTime"/>
         <result column="updateTime" property="updateTime"/>
-        <result column="orderId" property="orderId"/>
+        <result column="orderNo" property="orderNo"/>
         <result column="type" property="type"/>
         <result column="name" property="name"/>
         <result column="taxpayerIdentificationNumber" property="taxpayerIdentificationNumber"/>
@@ -26,9 +29,22 @@
         select * from workark_invoice where id = #{id}
     </select>
 
+    <select id="getOrderNo" resultMap="result">
+        select * from workark_invoice where orderNo = #{orderNo}
+    </select>
+
     <select id="getList" resultMap="result">
         select * from workark_invoice
         <where>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="userId != 0">
+                and userId = #{userId}
+            </if>
+            <if test="invoiceModelId != 0">
+                and invoiceModelId = #{invoiceModelId}
+            </if>
             <if test="orderNo != null">
                 and orderNo = #{orderNo}
             </if>
@@ -62,6 +78,15 @@
     <select id="getTotalCount" parameterType="com.bosshand.virgo.api.workark.model.Invoice" resultType="Integer">
         SELECT count(*) FROM workark_invoice
         <where>
+            <if test="invoiceModelId != 0">
+                and invoiceModelId = #{invoiceModelId}
+            </if>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="userId != 0">
+                and userId = #{userId}
+            </if>
             <if test="orderNo != null">
                 and orderNo = #{orderNo}
             </if>
@@ -95,6 +120,15 @@
     <select id="getLimit" resultMap="result">
         select * from workark_invoice
         <where>
+            <if test="p.invoiceModelId != 0">
+                and invoiceModelId = #{p.invoiceModelId}
+            </if>
+            <if test="p.organizationId != 0">
+                and organizationId = #{p.organizationId}
+            </if>
+            <if test="p.userId != 0">
+                and userId = #{p.userId}
+            </if>
             <if test="p.orderNo != null">
                 and orderNo = #{p.orderNo}
             </if>
@@ -127,17 +161,21 @@
     </select>
 
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO workark_invoice (`createTime`, `orderNo`, `type`, `name`, `taxpayerIdentificationNumber`, `address`, `phone`, `bankAccount`, `bankAccountNumber`, `content`, `amount`, `file`)
-        VALUES (now(), #{orderNo}, #{type}, #{name}, #{taxpayerIdentificationNumber}, #{address}, #{phone}, #{bankAccount}, #{bankAccountNumber}, #{content}, #{amount}, #{file})
+        INSERT INTO workark_invoice (`organizationId`, `userId`, `invoiceModelId`, `createTime`, `orderNo`, `type`, `name`, `taxpayerIdentificationNumber`, `address`, `phone`, `bankAccount`, `bankAccountNumber`, `content`, `amount`, `file`)
+        VALUES (#{organizationId}, #{userId}, #{invoiceModelId}, now(), #{orderNo}, #{type}, #{name}, #{taxpayerIdentificationNumber}, #{address}, #{phone}, #{bankAccount}, #{bankAccountNumber}, #{content}, #{amount}, #{file})
     </insert>
 
     <update id="update" parameterType="com.bosshand.virgo.api.workark.model.Invoice">
         UPDATE workark_invoice
         <trim prefix="set" suffixOverrides=",">
+            <if test="invoiceModelId != 0">invoiceModelId = #{invoiceModelId},</if>
+            <if test="organizationId != 0">organizationId = #{organizationId},</if>
+            <if test="userId != 0">userId = #{userId},</if>
             <if test="orderNo != null">orderNo = #{orderNo},</if>
             <if test="type != null">type = #{type},</if>
             <if test="name != null">name = #{name},</if>
             <if test="taxpayerIdentificationNumber != null">taxpayerIdentificationNumber = #{taxpayerIdentificationNumber},</if>
+            <if test="address != null">address = #{address},</if>
             <if test="phone != null">phone = #{phone},</if>
             <if test="bankAccount != null">bankAccount = #{bankAccount},</if>
             <if test="bankAccountNumber != null">bankAccountNumber = #{bankAccountNumber},</if>

+ 81 - 0
virgo.api/src/main/resources/mapper/InvoiceModelMapper.xml

@@ -0,0 +1,81 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.workark.dao.InvoiceModelDao">
+
+    <resultMap type="com.bosshand.virgo.api.workark.model.InvoiceModel" id="result">
+        <id column="id" property="id"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="userId" property="userId"/>
+        <result column="type" property="type"/>
+        <result column="name" property="name"/>
+        <result column="taxpayerIdentificationNumber" property="taxpayerIdentificationNumber"/>
+        <result column="address" property="address"/>
+        <result column="phone" property="phone"/>
+        <result column="bankAccount" property="bankAccount"/>
+        <result column="bankAccountNumber" property="bankAccountNumber"/>
+        <result column="content" property="content"/>
+    </resultMap>
+
+    <select id="get" resultMap="result">
+        select * from workark_invoice_model where id = #{id}
+    </select>
+
+    <select id="getList" resultMap="result">
+        select * from workark_invoice_model
+        <where>
+            <if test="organizationId != 0">
+                and organizationId = #{organizationId}
+            </if>
+            <if test="userId != 0">
+                and userId = #{userId}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="name != null">
+                and name = #{name}
+            </if>
+            <if test="taxpayerIdentificationNumber != null">
+                and taxpayerIdentificationNumber = #{taxpayerIdentificationNumber}
+            </if>
+            <if test="phone != null">
+                and phone = #{phone}
+            </if>
+            <if test="bankAccount != null">
+                and bankAccount = #{bankAccount}
+            </if>
+            <if test="bankAccountNumber != null">
+                and bankAccountNumber = #{bankAccountNumber}
+            </if>
+        </where>
+    </select>
+
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO workark_invoice_model (`organizationId`, `userId`, `type`, `name`, `taxpayerIdentificationNumber`, `address`, `phone`, `bankAccount`, `bankAccountNumber`, `content`)
+        VALUES (#{organizationId}, #{userId}, #{type}, #{name}, #{taxpayerIdentificationNumber}, #{address}, #{phone}, #{bankAccount}, #{bankAccountNumber}, #{content})
+    </insert>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.workark.model.Invoice">
+        UPDATE workark_invoice_model
+        <trim prefix="set" suffixOverrides=",">
+            <if test="organizationId != 0">organizationId = #{organizationId},</if>
+            <if test="userId != 0">userId = #{userId},</if>
+            <if test="type != null">type = #{type},</if>
+            <if test="name != null">name = #{name},</if>
+            <if test="taxpayerIdentificationNumber != null">taxpayerIdentificationNumber = #{taxpayerIdentificationNumber},</if>
+            <if test="address != null">address = #{address},</if>
+            <if test="phone != null">phone = #{phone},</if>
+            <if test="bankAccount != null">bankAccount = #{bankAccount},</if>
+            <if test="bankAccountNumber != null">bankAccountNumber = #{bankAccountNumber},</if>
+            <if test="content != null">content = #{content},</if>
+        </trim>
+        WHERE id=#{id}
+    </update>
+
+    <delete id="delete">
+        DELETE FROM workark_invoice_model WHERE id=#{id}
+    </delete>
+
+</mapper>