Commit f5ef1a9cdefe6f1aff52ac6adf3c78320f967f97

Authored by xqs
1 parent 30013a68

新增货主仓库对应关系修改

src/main/java/com/huaheng/pc/config/company/controller/CompanyController.java
... ... @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6 6 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7 +import com.huaheng.common.exception.service.ServiceException;
7 8 import com.huaheng.common.support.Convert;
8 9 import com.huaheng.common.utils.StringUtils;
9 10 import com.huaheng.common.utils.security.ShiroUtils;
... ... @@ -25,6 +26,7 @@ import org.springframework.ui.ModelMap;
25 26 import org.springframework.web.bind.annotation.*;
26 27  
27 28 import javax.annotation.Resource;
  29 +import java.util.Date;
28 30 import java.util.List;
29 31 import java.util.Map;
30 32  
... ... @@ -100,7 +102,12 @@ public class CompanyController extends BaseController {
100 102 @PostMapping("/add")
101 103 @ResponseBody
102 104 public AjaxResult addSave(Company company) {
  105 + if(StringUtils.isEmpty(company.getCode()) && StringUtils.isEmpty(company.getName())){
  106 + return AjaxResult.error("货主编码和名称不能为空!");
  107 + }
  108 + company.setCreated(new Date());
103 109 company.setCreatedBy(ShiroUtils.getLoginName());
  110 + company.setLastUpdated(new Date());
104 111 company.setLastUpdatedBy(ShiroUtils.getLoginName());
105 112 return companyService.addCompany(company);
106 113 }
... ...
src/main/java/com/huaheng/pc/config/company/mapper/CompanyMapper.java
... ... @@ -16,5 +16,7 @@ public interface CompanyMapper extends BaseMapper<Company> {
16 16  
17 17 List<Company> loginGetCompany(@Param("userId") Integer userId, @Param("warehouseCode") String warehouseCode);
18 18  
  19 + int insert(Company company);
  20 +
19 21  
20 22 }
21 23 \ No newline at end of file
... ...
src/main/java/com/huaheng/pc/config/company/service/CompanyServiceImpl.java
... ... @@ -3,6 +3,7 @@ package com.huaheng.pc.config.company.service;
3 3 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5 5 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6 +import com.huaheng.common.exception.service.ServiceException;
6 7 import com.huaheng.common.utils.StringUtils;
7 8 import com.huaheng.common.utils.security.ShiroUtils;
8 9 import com.huaheng.framework.web.domain.AjaxResult;
... ... @@ -66,24 +67,41 @@ public class CompanyServiceImpl extends ServiceImpl&lt;CompanyMapper, Company&gt; impl
66 67 return companys;
67 68 }
68 69  
  70 + /**
  71 + * 新增货主
  72 + * */
69 73 @Override
70 74 @Transactional(rollbackFor = Exception.class)
71 75 public AjaxResult addCompany(Company company) {
  76 +
72 77 String[] warehouse = company.getWarehouseCode().split(",");
73   - //更新货主
74   - company.setCreatedBy(ShiroUtils.getLoginName());
75   - company.setLastUpdatedBy(ShiroUtils.getLoginName());
76   - this.save(company);
77   - //添加货主仓库关联
  78 + company.setDeleted(false);
  79 + //添加货主及仓库关联
78 80 WarehouseCompany record = new WarehouseCompany();
79   - for (int i=0; i<warehouse.length-1; i++)
80   - {
  81 + for (int i=0; i < warehouse.length; i++){
  82 + String warehouseCode = warehouse[i];
  83 + company.setWarehouseCode(warehouseCode);
  84 + //校验同仓库有无重复code
  85 + LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
  86 + companyLambdaQueryWrapper.eq(Company::getCode,company.getCode());
  87 + companyLambdaQueryWrapper.eq(Company::getWarehouseCode,warehouseCode);
  88 + Company tmp = this.getOne(companyLambdaQueryWrapper);
  89 + if(!StringUtils.isNull(tmp)){
  90 + return AjaxResult.error("货主编码重复,请重新输入编码!");
  91 + }
  92 + int c = companyMapper.insert(company);
  93 + if(c < 1){
  94 + throw new ServiceException("插入货主失败!");
  95 + }
81 96 record.setCompanyId(company.getId());
82 97 record.setCompanyCode(company.getCode());
83   - record.setWarehouseCode(warehouse[i]);
84   - warehouseCompanyService.save(record);
  98 + record.setWarehouseCode(warehouseCode);
  99 + Boolean w = warehouseCompanyService.save(record);
  100 + if(!w){
  101 + throw new ServiceException("插入货主仓库关联失败!");
  102 + }
85 103 }
86   - return AjaxResult.success("更新成功!");
  104 + return AjaxResult.success("新增货主成功!");
87 105 }
88 106  
89 107 @Override
... ...
src/main/resources/mybatis/config/CompanyMapper.xml
... ... @@ -37,14 +37,16 @@
37 37 <result column="userDef7" jdbcType="VARCHAR" property="userDef7" />
38 38 <result column="userDef8" jdbcType="VARCHAR" property="userDef8" />
39 39 <result column="processStamp" jdbcType="VARCHAR" property="processStamp" />
  40 + <result column="deleted" jdbcType="BIT" property="deleted" />
40 41 </resultMap>
  42 +
41 43 <sql id="Base_Column_List">
42 44 <!--@mbg.generated-->
43 45 id, code, warehouseCode, `name`, attentionTo, address1, address2, district, city,
44 46 province, country, postalCode, phoneNum, mobile, email, shipmentPrefix, receiptPrefix,
45 47 nameEn, printDocAtChecked, hostInterfaceType, created, createdBy, lastUpdated, lastUpdatedBy,
46 48 version, userDef1, userDef2, userDef3, userDef4, userDef5, userDef6, userDef7, userDef8,
47   - processStamp
  49 + processStamp,deleted
48 50 </sql>
49 51  
50 52 <select id="loginGetCompany" resultType="com.huaheng.pc.config.company.domain.Company">
... ... @@ -54,7 +56,6 @@
54 56 INNER JOIN warehouse_company wc ON wc.companyId=c.id AND wc.warehouseCode = #{warehouseCode}
55 57 </select>
56 58  
57   -
58 59 <select id="selectCompanyByUserId" resultType="com.huaheng.pc.config.company.domain.Company">
59 60 SELECT c.id, c.name, c.code
60 61 FROM sys_user_company suc
... ... @@ -141,4 +142,218 @@
141 142 </where>
142 143 </select>
143 144  
  145 + <insert id="insert" parameterType="com.huaheng.pc.config.company.domain.Company" keyProperty="id" useGeneratedKeys="true" >
  146 + INSERT INTO company
  147 + <trim prefix="(" suffix=")" suffixOverrides=",">
  148 + <if test="code != null">
  149 + code,
  150 + </if>
  151 + <if test="warehouseCode != null">
  152 + warehouseCode,
  153 + </if>
  154 + <if test="name != null">
  155 + name,
  156 + </if>
  157 + <if test="attentionTo != null">
  158 + attentionTo,
  159 + </if>
  160 + <if test="address1 != null">
  161 + address1,
  162 + </if>
  163 + <if test="address2 != null">
  164 + address2,
  165 + </if>
  166 + <if test="district != null">
  167 + district,
  168 + </if>
  169 + <if test="city != null">
  170 + city,
  171 + </if>
  172 + <if test="province != null">
  173 + province,
  174 + </if>
  175 + <if test="country != null">
  176 + country,
  177 + </if>
  178 + <if test="postalCode != null">
  179 + postalCode,
  180 + </if>
  181 + <if test="phoneNum != null">
  182 + phoneNum,
  183 + </if>
  184 + <if test="mobile != null">
  185 + mobile,
  186 + </if>
  187 + <if test="email != null">
  188 + email,
  189 + </if>
  190 + <if test="shipmentPrefix != null">
  191 + shipmentPrefix,
  192 + </if>
  193 + <if test="receiptPrefix != null">
  194 + receiptPrefix,
  195 + </if>
  196 + <if test="nameEn != null">
  197 + nameEn,
  198 + </if>
  199 + <if test="printDocAtChecked != null">
  200 + printDocAtChecked,
  201 + </if>
  202 + <if test="hostInterfaceType != null">
  203 + hostInterfaceType,
  204 + </if>
  205 + <if test="created != null">
  206 + created,
  207 + </if>
  208 + <if test="createdBy != null">
  209 + createdBy,
  210 + </if>
  211 + <if test="lastUpdated != null">
  212 + lastUpdated,
  213 + </if>
  214 + <if test="lastUpdatedBy != null">
  215 + lastUpdatedBy,
  216 + </if>
  217 + <if test="version != null">
  218 + version,
  219 + </if>
  220 + <if test="userDef1 != null">
  221 + userDef1,
  222 + </if>
  223 + <if test="userDef2 != null">
  224 + userDef2,
  225 + </if>
  226 + <if test="userDef3 != null">
  227 + userDef3,
  228 + </if>
  229 + <if test="userDef4 != null">
  230 + userDef4,
  231 + </if>
  232 + <if test="userDef5 != null">
  233 + userDef5,
  234 + </if>
  235 + <if test="userDef6 != null">
  236 + userDef6,
  237 + </if>
  238 + <if test="userDef7 != null">
  239 + userDef7,
  240 + </if>
  241 + <if test="userDef8 != null">
  242 + userDef8,
  243 + </if>
  244 + <if test="processStamp != null">
  245 + processStamp,
  246 + </if>
  247 + <if test="deleted != null">
  248 + deleted,
  249 + </if>
  250 + </trim>
  251 + <trim prefix=" values (" suffix=")" suffixOverrides=",">
  252 + <if test="code != null">
  253 + #{code, jdbcType=VARCHAR},
  254 + </if>
  255 + <if test="warehouseCode != null">
  256 + #{warehouseCode, jdbcType=VARCHAR},
  257 + </if>
  258 + <if test="name != null">
  259 + #{name, jdbcType=VARCHAR},
  260 + </if>
  261 + <if test="attentionTo != null">
  262 + #{attentionTo, jdbcType=VARCHAR},
  263 + </if>
  264 + <if test="address1 != null">
  265 + #{address1, jdbcType=VARCHAR},
  266 + </if>
  267 + <if test="address2 != null">
  268 + #{address2, jdbcType=VARCHAR},
  269 + </if>
  270 + <if test="district != null">
  271 + #{district, jdbcType=VARCHAR},
  272 + </if>
  273 + <if test="city != null">
  274 + #{city, jdbcType=VARCHAR},
  275 + </if>
  276 + <if test="province != null">
  277 + #{province, jdbcType=VARCHAR},
  278 + </if>
  279 + <if test="country != null">
  280 + #{country, jdbcType=VARCHAR},
  281 + </if>
  282 + <if test="postalCode != null">
  283 + #{postalCode, jdbcType=VARCHAR},
  284 + </if>
  285 + <if test="phoneNum != null">
  286 + #{phoneNum, jdbcType=VARCHAR},
  287 + </if>
  288 + <if test="mobile != null">
  289 + #{mobile, jdbcType=VARCHAR},
  290 + </if>
  291 + <if test="email != null">
  292 + #{email, jdbcType=VARCHAR},
  293 + </if>
  294 + <if test="shipmentPrefix != null">
  295 + #{shipmentPrefix, jdbcType=VARCHAR},
  296 + </if>
  297 + <if test="receiptPrefix != null">
  298 + #{receiptPrefix, jdbcType=VARCHAR},
  299 + </if>
  300 + <if test="nameEn != null">
  301 + #{nameEn, jdbcType=VARCHAR},
  302 + </if>
  303 + <if test="printDocAtChecked != null">
  304 + #{printDocAtChecked, jdbcType=INTEGER},
  305 + </if>
  306 + <if test="hostInterfaceType != null">
  307 + #{hostInterfaceType, jdbcType=VARCHAR},
  308 + </if>
  309 + <if test="created != null">
  310 + #{created, jdbcType=TIMESTAMP},
  311 + </if>
  312 + <if test="createdBy != null">
  313 + #{createdBy, jdbcType=VARCHAR},
  314 + </if>
  315 + <if test="lastUpdated != null">
  316 + #{lastUpdated, jdbcType=TIMESTAMP},
  317 + </if>
  318 + <if test="lastUpdatedBy != null">
  319 + #{lastUpdatedBy, jdbcType=VARCHAR},
  320 + </if>
  321 + <if test="version != null">
  322 + #{version, jdbcType=INTEGER},
  323 + </if>
  324 + <if test="userDef1 != null">
  325 + #{userDef1, jdbcType=VARCHAR},
  326 + </if>
  327 + <if test="userDef2 != null">
  328 + #{userDef2, jdbcType=VARCHAR},
  329 + </if>
  330 + <if test="userDef3 != null">
  331 + #{userDef3, jdbcType=VARCHAR},
  332 + </if>
  333 + <if test="userDef4 != null">
  334 + #{userDef4, jdbcType=VARCHAR},
  335 + </if>
  336 + <if test="userDef5 != null">
  337 + #{userDef5, jdbcType=VARCHAR},
  338 + </if>
  339 + <if test="userDef6 != null">
  340 + #{userDef6, jdbcType=VARCHAR},
  341 + </if>
  342 + <if test="userDef7 != null">
  343 + #{userDef7, jdbcType=VARCHAR},
  344 + </if>
  345 + <if test="userDef8 != null">
  346 + #{userDef8, jdbcType=VARCHAR},
  347 + </if>
  348 + <if test="processStamp != null">
  349 + #{processStamp, jdbcType=VARCHAR},
  350 + </if>
  351 + <if test="deleted != null">
  352 + #{deleted, jdbcType=BIT},
  353 + </if>
  354 + </trim>
  355 + </insert>
  356 +
  357 +
  358 +
144 359 </mapper>
145 360 \ No newline at end of file
... ...
src/main/resources/templates/config/company/company.html
... ... @@ -64,7 +64,7 @@
64 64 {
65 65 field : 'id',
66 66 title : 'id',
67   - visible:false
  67 + visible:true
68 68 },
69 69 {
70 70 field : 'code',
... ...
src/main/resources/templates/system/user/edit.html
... ... @@ -79,7 +79,7 @@
79 79 <div class="form-group">
80 80 <label class="col-sm-3 control-label">角色:</label>
81 81 <div class="col-sm-8">
82   - <label th:each="role:${roles}" class="checkbox-inline i-checks">
  82 + <label th:each="role:${roles}" class="radio-inline i-checks">
83 83 <input name="role" type="radio" th:value="${role.id}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.enable == false}">
84 84 </label>
85 85 </div>
... ...