dcs преди 5 месеца
родител
ревизия
1130491caf

+ 59 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/controller/EncodingGeneratorController.java

@@ -0,0 +1,59 @@
+package com.bosshand.virgo.api.controller;
+
+import com.bosshand.virgo.api.model.Encoding;
+import com.bosshand.virgo.api.model.EncodingGenerator;
+import com.bosshand.virgo.api.service.EncodingGeneratorService;
+import com.bosshand.virgo.core.response.Response;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("encodingGenerator")
+@Api(tags = {"编码生成器"})
+public class EncodingGeneratorController {
+
+    @Autowired
+    EncodingGeneratorService encodingGeneratorService;
+
+    @ApiOperation(value = "生成编码", notes = "生成编码")
+    @RequestMapping(value = "", method = RequestMethod.POST)
+    public Response save(@RequestBody EncodingGenerator data) {
+        EncodingGenerator eg = encodingGeneratorService.generateCode(data);
+        if (encodingGeneratorService.getCode(eg.getCode()) != null) {
+            return Response.fail(200000, "自定义编码已存在");
+        }
+        encodingGeneratorService.save(eg);
+        return Response.ok(eg.getCode());
+    }
+
+    @ApiOperation(value = "查询编码类型", notes = "查询编码类型")
+    @RequestMapping(value = "/type/query", method = RequestMethod.POST)
+    public Response query(@RequestBody Encoding data) {
+        return Response.ok( encodingGeneratorService.get(data));
+    }
+
+    @ApiOperation(value = "新增编码类型", notes = "新增编码类型")
+    @RequestMapping(value = "/type", method = RequestMethod.POST)
+    public Response save(@RequestBody Encoding data) {
+        encodingGeneratorService.save(data);
+        return Response.ok();
+    }
+
+    @ApiOperation(value = "更新编码类型", notes = "更新编码类型")
+    @RequestMapping(value = "/type", method = RequestMethod.PUT)
+    public Response update(@RequestBody Encoding data) {
+        encodingGeneratorService.update(data);
+        return Response.ok();
+    }
+
+    @ApiOperation(value = "删除编码类型", notes = "删除编码类型")
+    @RequestMapping(value = "/type/{id}", method = RequestMethod.DELETE)
+    public Response delete(@PathVariable long id) {
+        encodingGeneratorService.delete(id);
+        return Response.ok();
+    }
+
+
+}

+ 18 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/EncodingDao.java

@@ -0,0 +1,18 @@
+package com.bosshand.virgo.api.dao;
+
+import com.bosshand.virgo.api.model.Encoding;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface EncodingDao {
+
+    int save(Encoding data);
+
+    int delete(long id);
+
+    int update(Encoding data);
+
+    List<Encoding> get(Encoding data);
+}

+ 15 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/EncodingGeneratorDao.java

@@ -0,0 +1,15 @@
+package com.bosshand.virgo.api.dao;
+
+import com.bosshand.virgo.api.model.EncodingGenerator;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface EncodingGeneratorDao {
+
+    int save(EncodingGenerator data);
+
+    EncodingGenerator getId();
+
+    EncodingGenerator get(String code);
+
+}

+ 56 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/Encoding.java

@@ -0,0 +1,56 @@
+package com.bosshand.virgo.api.model;
+
+/**
+ * 编码类型
+ */
+public class Encoding {
+
+    private long id;
+
+    /**
+     * 编码名称
+     */
+    private String name;
+
+    /**
+     * 编码类型
+     */
+    private int type;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+}

+ 82 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/EncodingGenerator.java

@@ -0,0 +1,82 @@
+package com.bosshand.virgo.api.model;
+
+/**
+ * 编码生成器
+ */
+public class EncodingGenerator {
+
+    private long id;
+
+    /**
+     * 年份
+     */
+    private String year;
+
+    /**
+     * 类别
+     */
+    private String type;
+
+    /**
+     * 位置
+     */
+    private String position;
+
+    /**
+     * 序号
+     */
+    private String number;
+
+    /**
+     * 生成编码结果
+     */
+    private String code;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getYear() {
+        return year;
+    }
+
+    public void setYear(String year) {
+        this.year = year;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getPosition() {
+        return position;
+    }
+
+    public void setPosition(String position) {
+        this.position = position;
+    }
+
+    public String getNumber() {
+        return number;
+    }
+
+    public void setNumber(String number) {
+        this.number = number;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+}

+ 67 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/EncodingGeneratorService.java

@@ -0,0 +1,67 @@
+package com.bosshand.virgo.api.service;
+
+import com.bosshand.virgo.api.dao.EncodingDao;
+import com.bosshand.virgo.api.dao.EncodingGeneratorDao;
+import com.bosshand.virgo.api.model.Encoding;
+import com.bosshand.virgo.api.model.EncodingGenerator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class EncodingGeneratorService {
+
+    @Autowired
+    EncodingDao encodingDao;
+
+    @Autowired
+    EncodingGeneratorDao encodingGeneratorDao;
+
+    private String generateNuber() {
+        long counter = 0;
+        EncodingGenerator eg = encodingGeneratorDao.getId();
+        if (eg != null) {
+            counter = eg.getId();
+        }
+        return String.format("%05d", ++counter);
+    }
+
+    public EncodingGenerator generateCode(EncodingGenerator data) {
+        String number = "";
+        if (data.getNumber() != null) {
+            number = data.getNumber();
+        } else {
+            number = generateNuber();
+        }
+        String code = data.getYear() + data.getType() + data.getPosition() + number;
+        data.setCode(code);
+        return data;
+    }
+
+    public EncodingGenerator getCode(String code) {
+        return encodingGeneratorDao.get(code);
+    }
+
+    public EncodingGenerator save(EncodingGenerator data) {
+        encodingGeneratorDao.save(data);
+        return data;
+    }
+
+    public int save(Encoding data) {
+        return encodingDao.save(data);
+    }
+
+    public int delete(long id) {
+        return encodingDao.delete(id);
+    }
+
+    public int update(Encoding data) {
+        return encodingDao.update(data);
+    }
+
+    public List<Encoding> get(Encoding data) {
+        return encodingDao.get(data);
+    }
+
+}

+ 30 - 0
virgo.api/src/main/resources/mapper/EncodingGeneratorMapper.xml

@@ -0,0 +1,30 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.dao.EncodingGeneratorDao">
+
+    <resultMap type="com.bosshand.virgo.api.model.EncodingGenerator" id="result">
+        <id column="id" property="id"/>
+        <result column="year" property="year"/>
+        <result column="type" property="type"/>
+        <result column="position" property="position"/>
+        <result column="number" property="number"/>
+        <result column="code" property="code"/>
+    </resultMap>
+
+    <insert id="save" parameterType="com.bosshand.virgo.api.model.EncodingGenerator" useGeneratedKeys="true" keyProperty="id">
+        insert into encoding_generator(year, type, position, number, code) VALUES
+            (#{year}, #{type}, #{position}, #{number}, #{code})
+    </insert>
+
+    <select id="get" resultMap="result">
+        SELECT * FROM encoding_generator where code = #{code}
+    </select>
+
+    <select id="getId" resultMap="result">
+        SELECT id FROM encoding_generator ORDER BY id DESC LIMIT 1;
+    </select>
+
+
+</mapper>

+ 44 - 0
virgo.api/src/main/resources/mapper/EncodingMapper.xml

@@ -0,0 +1,44 @@
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.bosshand.virgo.api.dao.EncodingDao">
+
+    <resultMap type="com.bosshand.virgo.api.model.Encoding" id="result">
+        <id column="id" property="id"/>
+        <result column="name" property="name"/>
+        <result column="type" property="type"/>
+        <result column="remark" property="remark"/>
+    </resultMap>
+
+    <insert id="save" parameterType="com.bosshand.virgo.api.model.Encoding" useGeneratedKeys="true" keyProperty="id">
+        insert into encoding(name, type, remark) VALUES (#{name}, #{type}, #{remark})
+    </insert>
+
+    <select id="get" resultMap="result">
+        SELECT * FROM encoding
+        <where>
+            <if test="type != 0">
+                and type = #{type}
+            </if>
+            <if test="name != null">
+                and name = #{name}
+            </if>
+        </where>
+    </select>
+
+    <delete id="delete">
+        DELETE FROM encoding where id = #{id}
+    </delete>
+
+    <update id="update" parameterType="com.bosshand.virgo.api.model.Encoding">
+        update encoding
+        <trim prefix="set" suffixOverrides=",">
+            <if test="name!=null">name=#{name},</if>
+            <if test="type!=0">type=#{type},</if>
+            <if test="remark!=null">remark=#{remark},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+</mapper>