Browse Source

币别汇率增加初始化设置,日志记录

chenw 7 years ago
parent
commit
feda1c42ea

+ 9 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/dto/InitStatusDTO.java

@@ -10,8 +10,17 @@ public class InitStatusDTO implements Serializable {
     private boolean product;
     private boolean product;
     private boolean customer;
     private boolean customer;
     private boolean vendor;
     private boolean vendor;
+    private boolean currency;
     private boolean begin;
     private boolean begin;
 
 
+    public boolean isCurrency() {
+        return currency;
+    }
+
+    public void setCurrency(boolean currency) {
+        this.currency = currency;
+    }
+
     public boolean isBegin() {
     public boolean isBegin() {
         return begin;
         return begin;
     }
     }

+ 4 - 0
applications/commons/commons-server/pom.xml

@@ -31,6 +31,10 @@
             <groupId>com.usoftchina.saas</groupId>
             <groupId>com.usoftchina.saas</groupId>
             <artifactId>sms-api</artifactId>
             <artifactId>sms-api</artifactId>
         </dependency>
         </dependency>
+        <dependency>
+          <groupId>com.usoftchina.saas</groupId>
+          <artifactId>document-api</artifactId>
+        </dependency>
         <!-- db -->
         <!-- db -->
         <dependency>
         <dependency>
             <groupId>mysql</groupId>
             <groupId>mysql</groupId>

+ 2 - 0
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/mapper/CommonMapper.java

@@ -12,5 +12,7 @@ public interface CommonMapper {
 
 
     int getCountVendor(@Param("companyId") Long companyId);
     int getCountVendor(@Param("companyId") Long companyId);
 
 
+    int getCountCurrency(@Param("companyId") Long companyId);
+
     void commonAudit(String sql);
     void commonAudit(String sql);
 }
 }

+ 4 - 0
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/impl/CommonServiceImpl.java

@@ -40,6 +40,10 @@ public class CommonServiceImpl implements CommonService {
         if (count > 0){
         if (count > 0){
             result.setVendor(true);
             result.setVendor(true);
         }
         }
+        count = commonMapper.getCountCurrency(companyId);
+        if (count > 0){
+            result.setCurrency(true);
+        }
         if (result.isBaseSet() && result.isWarehouse() && result.isProduct() && result.isCustomer() && result.isVendor()){
         if (result.isBaseSet() && result.isWarehouse() && result.isProduct() && result.isCustomer() && result.isVendor()){
             result.setBegin(true);
             result.setBegin(true);
         }
         }

+ 10 - 0
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/impl/ConfigsServiceImpl.java

@@ -9,6 +9,8 @@ import com.usoftchina.saas.commons.po.Configs;
 import com.usoftchina.saas.commons.service.ConfigsService;
 import com.usoftchina.saas.commons.service.ConfigsService;
 import com.usoftchina.saas.commons.service.MessageLogService;
 import com.usoftchina.saas.commons.service.MessageLogService;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.context.BaseContextHolder;
+import com.usoftchina.saas.document.api.CurrencyApi;
+import com.usoftchina.saas.document.dto.CurrencyDTO;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.page.PageDefault;
 import com.usoftchina.saas.page.PageDefault;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.page.PageRequest;
@@ -29,6 +31,8 @@ public class ConfigsServiceImpl implements ConfigsService{
     private ConfigsMapper configsMapper;
     private ConfigsMapper configsMapper;
     @Autowired
     @Autowired
     private MessageLogService messageLogService;
     private MessageLogService messageLogService;
+    @Autowired
+    private CurrencyApi currencyApi;
 
 
 
 
     @Override
     @Override
@@ -95,6 +99,12 @@ public class ConfigsServiceImpl implements ConfigsService{
         }
         }
         for (Configs con : data) {
         for (Configs con : data) {
             con.setCompanyId(BaseContextHolder.getCompanyId());
             con.setCompanyId(BaseContextHolder.getCompanyId());
+            if ("defaultCurrency".equals(con.getCode())){
+                CurrencyDTO currencyDTO = new CurrencyDTO();
+                currencyDTO.setCr_name(con.getData());
+                currencyDTO.setCr_standard(1L);
+                currencyApi.setStandard(currencyDTO);
+            }
             configsMapper.updateByCodeSelective(con);
             configsMapper.updateByCodeSelective(con);
         }
         }
         DocBaseDTO baseDTO = new DocBaseDTO(null, "", "Configs");
         DocBaseDTO baseDTO = new DocBaseDTO(null, "", "Configs");

+ 4 - 0
applications/commons/commons-server/src/main/resources/mapper/CommonMapper.xml

@@ -15,6 +15,10 @@
         SELECT COUNT(*) FROM VENDOR WHERE COMPANYID=#{companyId} AND VE_STATUSCODE = 'ENABLE'
         SELECT COUNT(*) FROM VENDOR WHERE COMPANYID=#{companyId} AND VE_STATUSCODE = 'ENABLE'
     </select>
     </select>
 
 
+    <select id="getCountCurrency" resultType="int">
+        select count(*) from configs where companyId = #{companyId} and code = 'defaultCurrency' and data is not null;
+    </select>
+
     <update id="commonAudit" parameterType="string">
     <update id="commonAudit" parameterType="string">
       ${value}
       ${value}
     </update>
     </update>

+ 16 - 0
applications/document/document-api/src/main/java/com/usoftchina/saas/document/api/CurrencyApi.java

@@ -0,0 +1,16 @@
+package com.usoftchina.saas.document.api;
+
+import com.usoftchina.saas.auth.client.interceptor.ServiceFeignInterceptor;
+import com.usoftchina.saas.base.Result;
+import com.usoftchina.saas.document.dto.CurrencyDTO;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+@FeignClient(name = "document-server", configuration = ServiceFeignInterceptor.class)
+public interface CurrencyApi {
+
+    @PostMapping("/currency/setStandard")
+    Result setStandard(@RequestBody CurrencyDTO currencyDTO);
+
+}

+ 5 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/controller/CurrencyController.java

@@ -39,4 +39,9 @@ public class CurrencyController {
         return Result.success();
         return Result.success();
     }
     }
 
 
+    @PostMapping("/setStandard")
+    public Result setStandard(@RequestBody CurrencyDTO currencyDTO){
+        currencyService.setStandard(currencyDTO);
+        return Result.success();
+    }
 }
 }

+ 5 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/CurrencyMapper.java

@@ -10,4 +10,9 @@ public interface CurrencyMapper extends CommonBaseMapper<Currency> {
 
 
     List<Currency> getAll(@Param("condition") String condition, @Param("companyId") Long companyId);
     List<Currency> getAll(@Param("condition") String condition, @Param("companyId") Long companyId);
 
 
+    void clearStandard(@Param("companyId") Long companyId);
+
+    void setStandard(@Param("name") String name, @Param("companyId") Long companyId, @Param("standard") Long standard);
+
+    int selectCountByName(@Param("name") String name, @Param("companyId") Long companyId);
 }
 }

+ 1 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/CurrencyService.java

@@ -14,4 +14,5 @@ public interface CurrencyService  extends CommonBaseService<CurrencyMapper, Curr
 
 
     PageInfo<Currency> getAll(PageRequest pageRequest, ListReqDTO listReqDTO);
     PageInfo<Currency> getAll(PageRequest pageRequest, ListReqDTO listReqDTO);
 
 
+    void setStandard(CurrencyDTO currencyDTO);
 }
 }

+ 33 - 2
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/CurrencyServiceImpl.java

@@ -3,14 +3,19 @@ package com.usoftchina.saas.document.service.impl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
 import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
 import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
+import com.usoftchina.saas.commons.api.MessageLogService;
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
 import com.usoftchina.saas.commons.dto.ListReqDTO;
 import com.usoftchina.saas.commons.dto.ListReqDTO;
+import com.usoftchina.saas.commons.exception.BizExceptionCode;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.document.dto.CurrencyDTO;
 import com.usoftchina.saas.document.dto.CurrencyDTO;
 import com.usoftchina.saas.document.entities.Currency;
 import com.usoftchina.saas.document.entities.Currency;
 import com.usoftchina.saas.document.mapper.CurrencyMapper;
 import com.usoftchina.saas.document.mapper.CurrencyMapper;
 import com.usoftchina.saas.document.service.CurrencyService;
 import com.usoftchina.saas.document.service.CurrencyService;
+import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.page.PageRequest;
 import com.usoftchina.saas.utils.BeanMapper;
 import com.usoftchina.saas.utils.BeanMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.util.List;
 import java.util.List;
@@ -22,14 +27,27 @@ import java.util.List;
 @Service
 @Service
 public class CurrencyServiceImpl extends CommonBaseServiceImpl<CurrencyMapper, Currency> implements CurrencyService {
 public class CurrencyServiceImpl extends CommonBaseServiceImpl<CurrencyMapper, Currency> implements CurrencyService {
 
 
+    @Autowired
+    private MessageLogService messageLogService;
 
 
     @Override
     @Override
     public void save(CurrencyDTO currencyDTO) {
     public void save(CurrencyDTO currencyDTO) {
+        Currency currency = BeanMapper.map(currencyDTO, Currency.class);
+        Long companyId = BaseContextHolder.getCompanyId();
+        DocBaseDTO docBaseDTO = null;
         if (currencyDTO.getId() == 0){
         if (currencyDTO.getId() == 0){
-
+            currency.setCompanyId(companyId);
+            int count = getMapper().selectCountByName(currency.getCr_name(), companyId);
+            if (count > 0){
+                throw new BizException(BizExceptionCode.REPEAT_NAME);
+            }
+            getMapper().insertSelective(currency);
+            docBaseDTO = generateMsgObj(currency.getId());
+            messageLogService.save(docBaseDTO);
         }else{
         }else{
-            Currency currency = BeanMapper.map(currencyDTO, Currency.class);
             getMapper().updateByPrimaryKeySelective(currency);
             getMapper().updateByPrimaryKeySelective(currency);
+            docBaseDTO = generateMsgObj(currency.getId());
+            messageLogService.update(docBaseDTO);
         }
         }
     }
     }
 
 
@@ -41,4 +59,17 @@ public class CurrencyServiceImpl extends CommonBaseServiceImpl<CurrencyMapper, C
         PageInfo<Currency> pageInfo = new PageInfo<Currency>(currencyList);
         PageInfo<Currency> pageInfo = new PageInfo<Currency>(currencyList);
         return pageInfo;
         return pageInfo;
     }
     }
+
+    @Override
+    public void setStandard(CurrencyDTO currencyDTO) {
+        Long companyId = BaseContextHolder.getCompanyId();
+        getMapper().clearStandard(companyId);
+        getMapper().setStandard(currencyDTO.getCr_name(), companyId, currencyDTO.getCr_standard());
+
+    }
+
+    private DocBaseDTO generateMsgObj(Long id){
+        return new DocBaseDTO(id, "", "Currency");
+    }
+
 }
 }

+ 12 - 0
applications/document/document-server/src/main/resources/mapper/CurrencyMapper.xml

@@ -28,6 +28,9 @@
         where cr_id = #{id}
         where cr_id = #{id}
     </delete>
     </delete>
     <insert id="insertSelective" parameterType="com.usoftchina.saas.document.entities.Currency" >
     <insert id="insertSelective" parameterType="com.usoftchina.saas.document.entities.Currency" >
+        <selectKey resultType="java.lang.Long" keyProperty="id">
+          SELECT LAST_INSERT_ID() AS ID
+        </selectKey>
         insert into Currencys
         insert into Currencys
         <trim prefix="(" suffix=")" suffixOverrides="," >
         <trim prefix="(" suffix=")" suffixOverrides="," >
             <if test="cr_name != null" >
             <if test="cr_name != null" >
@@ -127,4 +130,13 @@
       </where>
       </where>
       ORDER BY CR_ID DESC
       ORDER BY CR_ID DESC
     </select>
     </select>
+    <update id="clearStandard">
+      UPDATE CURRENCYS SET CR_STANDARD = 0 WHERE COMPANYID = #{companyId}
+    </update>
+    <update id="setStandard">
+      UPDATE CURRENCYS SET CR_STANDARD = #{standard} WHERE COMPANYID = #{companyId} AND CR_NAME = #{name}
+    </update>
+    <select id="selectCountByName" resultType="int">
+      SELECT COUNT(*) FROM CURRENCYS WHERE CR_NAME = #{name} AND COMPANYID = #{companyId}
+    </select>
 </mapper>
 </mapper>